From 612cec3d1e46adff6953252f737d5611fe92222c Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Wed, 15 Apr 2026 15:07:30 +0200 Subject: [PATCH] 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+ --- test/conftest.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 0a3dcb693..ceaf2ebfd 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,5 +1,6 @@ import os import platform +import tempfile from pathlib import Path import pytest @@ -13,10 +14,22 @@ # interference with tests. # This ignores ~/.hgrc os.environ["HGRCPATH"] = "" -# This ignores system-level git config (eg: in /etc). There apperas to be -# no way to ignore ~/.gitconfig other than overriding $HOME, which is overkill. +# This ignores system-level git config (eg: in /etc). os.environ["GIT_CONFIG_NOSYSTEM"] = "1" + +@pytest.fixture(scope="session", autouse=True) +def git_global_config(): + # run-task writes to the global git config, so point it at a real + # (writable) empty file instead of ~/.gitconfig. + fd, path = tempfile.mkstemp(prefix="taskgraph-gitconfig-") + os.close(fd) + os.environ["GIT_CONFIG_GLOBAL"] = path + yield + del os.environ["GIT_CONFIG_GLOBAL"] + os.unlink(path) + + # Some of the tests marked with this may be fixable on Windows; we should # look into these in more depth at some point. nowin = pytest.mark.skipif(