Skip to content

Commit a76b719

Browse files
committed
isolate
1 parent de8d16a commit a76b719

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

.github/workflows/tests.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ name: Tests
22
on: push
33
jobs:
44
tests:
5-
runs-on: ubuntu-latest
5+
runs-on: ${{ matrix.os }}
66
strategy:
77
matrix:
8+
os: [ubuntu-20.04, windows-latest, macos-latest]
89
python-version: ['3.7', '3.8', '3.9', '3.10']
910
name: Python ${{ matrix.python-version }}
1011
steps:

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ install_requires=
3737
dev =
3838
pytest==6.2.5
3939
pytest-sugar==0.9.4
40-
pytest-test-utils==0.0.4
40+
pytest-test-utils==0.0.5
4141
pytest-cov==3.0.0
4242
pytest-mock==3.6.1
4343
pylint==2.11.1

tests/conftest.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,46 @@
1+
import os
2+
import sys
3+
4+
import pygit2
15
import pytest
2-
from pytest_test_utils import TmpDir
6+
from pytest_test_utils import TempDirFactory, TmpDir
37

48
from scmrepo.git import Git
59

610

7-
@pytest.fixture
8-
def scm(tmp_dir: TmpDir, monkeypatch: pytest.MonkeyPatch):
11+
@pytest.fixture(autouse=True)
12+
def isolate(tmp_dir_factory: TempDirFactory, monkeypatch: pytest.MonkeyPatch):
13+
path = tmp_dir_factory.mktemp("mock")
14+
home_dir = path / "home"
15+
home_dir.mkdir()
16+
17+
if sys.platform == "win32":
18+
home_drive, home_path = os.path.splitdrive(home_dir)
19+
monkeypatch.setenv("USERPROFILE", str(home_dir))
20+
monkeypatch.setenv("HOMEDRIVE", home_drive)
21+
monkeypatch.setenv("HOMEPATH", home_path)
22+
else:
23+
monkeypatch.setenv("HOME", str(home_dir))
24+
925
monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1")
10-
monkeypatch.setenv("GIT_AUTHOR_NAME", "DVC test user")
11-
monkeypatch.setenv("GIT_AUTHOR_EMAIL", "dvctester@example.com")
26+
contents = b"""
27+
[user]
28+
name=DVC Tester
29+
email=dvctester@example.com
30+
[init]
31+
defaultBranch=master
32+
"""
33+
(home_dir / ".gitconfig").write_bytes(contents)
34+
pygit2.settings.search_path[pygit2.GIT_CONFIG_LEVEL_GLOBAL] = str(home_dir)
1235

36+
37+
@pytest.fixture
38+
def scm(tmp_dir: TmpDir):
1339
git_ = Git.init(tmp_dir)
40+
sig = git_.pygit2.default_signature
41+
42+
assert sig.email == "dvctester@example.com"
43+
assert sig.name == "DVC Tester"
44+
1445
yield git_
1546
git_.close()

0 commit comments

Comments
 (0)