Skip to content

Commit 45626d3

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).
1 parent 9075117 commit 45626d3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

test/conftest.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import atexit
12
import os
23
import platform
4+
import tempfile
35
from pathlib import Path
46

57
import pytest
@@ -13,9 +15,14 @@
1315
# interference with tests.
1416
# This ignores ~/.hgrc
1517
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.
18+
# This ignores system-level git config (eg: in /etc).
1819
os.environ["GIT_CONFIG_NOSYSTEM"] = "1"
20+
# run-task writes to the global git config, so point it at a real
21+
# (writable) empty file instead of ~/.gitconfig.
22+
fd, git_global_path = tempfile.mkstemp(prefix="taskgraph-gitconfig-")
23+
os.close(fd)
24+
atexit.register(lambda: os.unlink(git_global_path))
25+
os.environ["GIT_CONFIG_GLOBAL"] = git_global_path
1926

2027
# Some of the tests marked with this may be fixable on Windows; we should
2128
# look into these in more depth at some point.

0 commit comments

Comments
 (0)