From 64c42fd50642b247b1e45d9f0e23c2f96fdcbad7 Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:24:28 +0100 Subject: [PATCH] Isolate fake GitHub tests from caller credentials Co-Authored-By: Codex --- tests/conftest.py | 10 ++++++++-- tests/test_gh_contract.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index e0f43426..7fb3c9e8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,12 +14,18 @@ GIT_ENV = {"GIT_CONFIG_GLOBAL": "/dev/null", "GIT_CONFIG_NOSYSTEM": "1"} -@pytest.fixture(autouse=True) -def no_real_app_helper(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: +def isolate_github_auth(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + for name in ("GH_TOKEN", "GITHUB_TOKEN"): + monkeypatch.delenv(name, raising=False) monkeypatch.setattr(github, "APP_TOKEN_HELPER", tmp_path / "absent-app-token", raising=False) monkeypatch.setattr(github, "_app_token_cache", ("", 0.0), raising=False) +@pytest.fixture(autouse=True) +def no_host_github_credentials(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + isolate_github_auth(tmp_path, monkeypatch) + + for _role in ("AUTHOR", "COMMITTER"): GIT_ENV |= {f"GIT_{_role}_NAME": "test", f"GIT_{_role}_EMAIL": "test@example.com"} diff --git a/tests/test_gh_contract.py b/tests/test_gh_contract.py index 7a06d0e9..bebf7f92 100644 --- a/tests/test_gh_contract.py +++ b/tests/test_gh_contract.py @@ -13,6 +13,7 @@ from loopzero import github from loopzero.types import Finding, ReviewResult +from tests.conftest import isolate_github_auth from tests.test_github import ( HEAD, PR_FILES, @@ -50,8 +51,7 @@ def captured_argv(tmp_path_factory: pytest.TempPathFactory) -> list[dict]: with pytest.MonkeyPatch.context() as env: env.setenv("PATH", str(tmp_path), prepend=os.pathsep) - env.setattr(github, "APP_TOKEN_HELPER", tmp_path / "absent-app-token") - env.setattr(github, "_app_token_cache", ("", 0.0)) + isolate_github_auth(tmp_path, env) github.pr_for_branch(REPO, "lz/x") github.pr_view(REPO, 7) github.create_draft_pr(REPO, "lz/x", "main", "Title", "Body\n")