Skip to content

Commit 1f6972b

Browse files
committed
Prevent tests from using the user and system git config
This prevents tests from asking to sign dummy commits on that repo if there's a global gpgsign config set. This also has the nice side effect of having the same tests not pollute the user git config with random safe directories (since run_task calls `git config --global` which tests exercise). We cannot use a `NamedTemporaryFile` here because windows doesn't like it when 2 processes have the same file open, and because delete_on_close is python3.12+
1 parent 9075117 commit 1f6972b

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

test/conftest.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import platform
3+
import tempfile
34
from pathlib import Path
45

56
import pytest
@@ -13,10 +14,21 @@
1314
# interference with tests.
1415
# This ignores ~/.hgrc
1516
os.environ["HGRCPATH"] = ""
16-
# This ignores system-level git config (eg: in /etc). There apperas to be
17-
# no way to ignore ~/.gitconfig other than overriding $HOME, which is overkill.
17+
# This ignores system-level git config (eg: in /etc).
1818
os.environ["GIT_CONFIG_NOSYSTEM"] = "1"
1919

20+
21+
@pytest.fixture(scope="session", autouse=True)
22+
def git_global_config():
23+
# run-task writes to the global git config, so point it at a real
24+
# (writable) empty file instead of ~/.gitconfig.
25+
fd, path = tempfile.mkstemp(prefix="taskgraph-gitconfig-")
26+
os.close(fd)
27+
os.environ["GIT_CONFIG_GLOBAL"] = path
28+
yield
29+
del os.environ["GIT_CONFIG_GLOBAL"]
30+
os.unlink(path)
31+
2032
# Some of the tests marked with this may be fixable on Windows; we should
2133
# look into these in more depth at some point.
2234
nowin = pytest.mark.skipif(

0 commit comments

Comments
 (0)