Skip to content

Commit f1e580a

Browse files
ferringbarthurzam
authored andcommitted
use a fake $HOME for tests
git uses both repo/.git/config and $HOME/.gitconfig, thus the tests have been picking up my commit.gpgsign=1 . Whilst pkgcore's git repo fixture can be tweaked to add that suppression, hygenically it's better to disconnect the users persona configuration from tests in full. TL;dr: this stops tests from popping a gpg key decrypt randomly for my local dev. Signed-off-by: Brian Harring <[email protected]> Part-of: #215 Closes: #215 Signed-off-by: Arthur Zamarin <[email protected]>
1 parent 0d80eaf commit f1e580a

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

tests/conftest.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
1+
import os
2+
import shutil
3+
import tempfile
4+
15
import pytest
6+
from snakeoil.cli import arghparse
7+
28
from pkgdev.cli import Tool
39
from pkgdev.scripts import pkgdev
4-
from snakeoil.cli import arghparse
510

611
pytest_plugins = ["pkgcore"]
712

813

914
@pytest.fixture(scope="session")
10-
def tool():
15+
def temporary_home():
16+
"""Generate a temporary directory and set$HOME to it."""
17+
old_home = os.environ.get("HOME")
18+
new_home = None
19+
try:
20+
new_home = tempfile.mkdtemp()
21+
os.environ["HOME"] = new_home
22+
yield
23+
finally:
24+
if old_home is None:
25+
del os.environ["HOME"]
26+
else:
27+
os.environ["HOME"] = old_home
28+
shutil.rmtree(new_home) # pyright: ignore[reportArgumentType]
29+
30+
31+
@pytest.fixture(scope="session")
32+
def tool(temporary_home):
1133
"""Generate a tool utility for running pkgdev."""
1234
return Tool(pkgdev.argparser)
1335

0 commit comments

Comments
 (0)