Tests unter git rebase --exec schreiben nicht ins Repo #51
No files matched your search
@@ -0,0 +1,19 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
# Only these git variables survive; they keep the user's and system git config out.
|
||||||
|
_GIT_ENV: dict[str, str] = {"GIT_CONFIG_GLOBAL": "/dev/null", "GIT_CONFIG_NOSYSTEM": "1"}
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_configure(config: pytest.Config) -> None:
|
||||||
|
"""Keep git in tests away from the repository and config running them.
|
||||||
|
|
||||||
|
`git rebase --exec` and hooks export GIT_DIR and friends, `git -c` exports
|
||||||
|
GIT_CONFIG_PARAMETERS; without this, `git init` and `git commit` in a test
|
||||||
|
would act on the checkout itself or run its hooks. Runs before collection,
|
||||||
|
so session fixtures and import-time code are covered too.
|
||||||
|
"""
|
||||||
|
for name in [name for name in os.environ if name.startswith("GIT_")]:
|
||||||
|
del os.environ[name]
|
||||||
|
os.environ.update(_GIT_ENV)
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import pytest
|
|
||||||
|
|
||||||
from chemenu.evals.baseline import GIT_REPO_ENV
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def _isolated_git(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
||||||
"""Keep git in tests away from the repository running them.
|
|
||||||
|
|
||||||
`git rebase --exec` and hooks export GIT_DIR; without this, `git init` and
|
|
||||||
`git commit` in a test would act on the checkout itself.
|
|
||||||
"""
|
|
||||||
for name in GIT_REPO_ENV:
|
|
||||||
monkeypatch.delenv(name, raising=False)
|
|
||||||
monkeypatch.setenv("GIT_CONFIG_GLOBAL", "/dev/null")
|
|
||||||
monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1")
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def test_git_repo_env_is_removed() -> None:
|
||||||
|
leaked = [
|
||||||
|
n
|
||||||
|
for n in os.environ
|
||||||
|
if n.startswith("GIT_")
|
||||||
|
and n
|
||||||
|
not in {
|
||||||
|
"GIT_CONFIG_GLOBAL",
|
||||||
|
"GIT_CONFIG_NOSYSTEM",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
assert leaked == []
|
||||||
|
assert os.environ["GIT_CONFIG_GLOBAL"] == "/dev/null"
|
||||||
|
assert os.environ["GIT_CONFIG_NOSYSTEM"] == "1"
|
||||||
Reference in new issue
Block a user