Skip to content

Commit 9fae9f6

Browse files
authored
isolate git config in tests (#449)
1 parent 59b7af0 commit 9fae9f6

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

.github/workflows/check-test-release.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,7 @@ jobs:
4141

4242
- run: pip install .[dev]
4343
- uses: pre-commit/[email protected]
44-
- name: Run tests
45-
run: |
46-
git config --global user.email "[email protected]"
47-
git config --global user.name "Olivaw"
48-
pytest
49-
env:
50-
GITHUB_MATRIX_OS: ${{ matrix.os }}
51-
GITHUB_MATRIX_PYTHON: ${{ matrix.python }}
44+
- run: pytest
5245

5346
- name: "Upload coverage to Codecov"
5447
uses: codecov/codecov-action@v4

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Source = "https://github.com/iterative/gto"
4040
[project.optional-dependencies]
4141
tests = [
4242
"freezegun",
43+
"pygit2",
4344
"pytest",
4445
"pytest-cov",
4546
"pytest-mock",
@@ -104,7 +105,7 @@ extend-select = ["I", "B", "C4", "C90", "T10", "Q"]
104105
known-first-party = ["gto", "tests"]
105106

106107
[tool.pylint.master]
107-
extension-pkg-whitelist = ["pydantic", "pytest-lazy-fixture", "pytest"]
108+
extension-pkg-whitelist = ["pydantic", "pytest-lazy-fixture", "pygit2", "pytest"]
108109
load-plugins= ["pylint.extensions.no_self_use"]
109110

110111
[tool.pylint.message_control]

tests/conftest.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# pylint: disable=redefined-outer-name
2+
import os
23
import sys
34
from time import sleep
4-
from typing import Tuple
5+
from typing import Iterator, Tuple
56

7+
import pygit2
68
import pytest
79
from click.testing import Result
810
from pytest_test_utils import TmpDir
@@ -27,6 +29,34 @@ def runner() -> Runner:
2729
return Runner()
2830

2931

32+
@pytest.fixture(scope="session", autouse=True)
33+
def isolate(tmp_path_factory: pytest.TempPathFactory) -> Iterator[None]:
34+
path = tmp_path_factory.mktemp("mock")
35+
home_dir = path / "home"
36+
home_dir.mkdir()
37+
38+
monkeypatch = pytest.MonkeyPatch()
39+
if sys.platform == "win32":
40+
home_drive, home_path = os.path.splitdrive(home_dir)
41+
monkeypatch.setenv("USERPROFILE", str(home_dir))
42+
monkeypatch.setenv("HOMEDRIVE", home_drive)
43+
monkeypatch.setenv("HOMEPATH", home_path)
44+
else:
45+
monkeypatch.setenv("HOME", str(home_dir))
46+
47+
monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1")
48+
contents = b"""
49+
[user]
50+
name=GTO Tester
51+
52+
"""
53+
(home_dir / ".gitconfig").write_bytes(contents)
54+
pygit2.settings.search_path[pygit2.GIT_CONFIG_LEVEL_GLOBAL] = str(home_dir)
55+
56+
yield
57+
monkeypatch.undo()
58+
59+
3060
@pytest.fixture
3161
def scm(tmp_dir: TmpDir) -> Git:
3262
scm_instance = Git.init(tmp_dir)

0 commit comments

Comments
 (0)