diff --git a/tools/pr-management/tests/stats/test_json_parity.py b/tools/pr-management/tests/stats/test_json_parity.py index cb72dc574..e3a1bbf04 100644 --- a/tools/pr-management/tests/stats/test_json_parity.py +++ b/tools/pr-management/tests/stats/test_json_parity.py @@ -28,6 +28,8 @@ import json +import pytest + from pr_management.stats import dashboard, reference from .helpers import comment, make_pr @@ -78,6 +80,17 @@ def fake_paginated_search(query, search_q, *args, status=None, **kwargs): monkeypatch.setattr(module, "paginated_search", fake_paginated_search) monkeypatch.setattr(module, "fetch_codeowners", lambda repo: "") monkeypatch.setattr(module, "fetch_ready_pr_files", lambda repo, nums: {}) + if module is dashboard: + # dashboard.main() ends by publishing to a secret gist through `gh`. + # A unit test must never reach GitHub, so fail loudly if it gets there. + def refuse_publish(*args, **kwargs): + pytest.fail("unit test reached the dashboard gist publish step") + + # Guard each entry point independently of main()'s current call order. + monkeypatch.setattr(module, "gist_scope_available", refuse_publish) + monkeypatch.setattr(module, "publish_gist", refuse_publish) + monkeypatch.setattr(module, "read_stats_gist_id", refuse_publish) + monkeypatch.setattr(module, "store_stats_gist_id", refuse_publish) def _run(monkeypatch, module, out_path): @@ -93,6 +106,8 @@ def _run(monkeypatch, module, out_path): "--out", str(out_path), ] + if module is dashboard: + argv.append("--no-publish") # reference.py has no publish step and no such flag monkeypatch.setattr(module.sys, "argv", argv) module.main() return json.loads(out_path.with_suffix(".json").read_text())