Skip to content

Only make config more permissive in tests that need it #1648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Set protocol.file.allow only in tests that need it
Instead of setting environment variables just on CI and for the
the entire pytest command, this has the two test cases that need
protocol.file.allow to be set to "always" (instead of "user") set
them, via a shared fixture, just while those tests are running.

Both on CI and for local test runs, this makes it no longer
necessary to set this in a global configuration or through
environment variables, reducing the setup needed to run the tests.
  • Loading branch information
EliahKagan authored Sep 6, 2023
commit 4f594cd2cbf68caabb7d3f22397104f5aa1b49b7
4 changes: 0 additions & 4 deletions .github/workflows/cygwin-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,4 @@ jobs:
shell: bash.exe -eo pipefail -o igncr "{0}"
run: |
/usr/bin/python -m pytest
env:
GIT_CONFIG_COUNT: "1"
GIT_CONFIG_KEY_0: protocol.file.allow
GIT_CONFIG_VALUE_0: always
continue-on-error: false
4 changes: 0 additions & 4 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ jobs:
run: |
set -x
pytest
env:
GIT_CONFIG_COUNT: "1"
GIT_CONFIG_KEY_0: protocol.file.allow
GIT_CONFIG_VALUE_0: always
continue-on-error: false

- name: Documentation
Expand Down
22 changes: 21 additions & 1 deletion test/test_submodule.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
import contextlib
import os
import shutil
import tempfile
from pathlib import Path
import sys
from unittest import skipIf
from unittest import mock, skipIf

import pytest

Expand All @@ -31,6 +32,23 @@
import os.path as osp


@contextlib.contextmanager
def _allow_file_protocol():
"""Temporarily set protocol.file.allow to always, using environment variables."""
pair_index = int(os.getenv("GIT_CONFIG_COUNT", "0"))

# This is recomputed each time the context is entered, for compatibility with
# existing GIT_CONFIG_* environment variables, even if changed in this process.
patcher = mock.patch.dict(os.environ, {
"GIT_CONFIG_COUNT": str(pair_index + 1),
f"GIT_CONFIG_KEY_{pair_index}": "protocol.file.allow",
f"GIT_CONFIG_VALUE_{pair_index}": "always",
})

with patcher:
yield


class TestRootProgress(RootUpdateProgress):
"""Just prints messages, for now without checking the correctness of the states"""

Expand Down Expand Up @@ -709,6 +727,7 @@ def test_add_empty_repo(self, rwdir):
# end for each checkout mode

@with_rw_directory
@_allow_file_protocol()
def test_list_only_valid_submodules(self, rwdir):
repo_path = osp.join(rwdir, "parent")
repo = git.Repo.init(repo_path)
Expand Down Expand Up @@ -737,6 +756,7 @@ def test_list_only_valid_submodules(self, rwdir):
""",
)
@with_rw_directory
@_allow_file_protocol()
def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
parent = git.Repo.init(osp.join(rwdir, "parent"))
parent.git.submodule("add", self._small_repo_url(), "module")
Expand Down