From 3b0fbc426d2f3b5def27fa498a38c5988ba40d20 Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Tue, 15 Sep 2026 21:10:08 -0700 Subject: [PATCH 1/4] fix(tests): resolve the integration support package without run.py's PYTHONPATH tests/integration/conftest.py imported the bare `integration` package. Because tests/__init__.py and tests/integration/__init__.py both exist, pytest's default prepend import mode puts only the repo root on sys.path, so that name resolved only under the PYTHONPATH that tests/integration/run.py injects. Every other invocation died at conftest import with ModuleNotFoundError: No module named 'integration' and exit 4, including the command test_oci_integration.py documents in its own docstring. The imports now use the tests.integration._support path that pytest actually resolves, matching the 120 other `from tests.` imports in the suite. run.py's PYTHONPATH still works because it already puts the repo root on the path. tests/code_coverage_tests/test_integration_suite_imports.py collects every file under tests/integration with PYTHONPATH scrubbed and asserts a non-zero collection count, so an unresolvable import fails the code-quality job instead of only the developers who run these files by hand. CI runs the three pre-existing files through the allowlist rather than executing them, which is why nothing caught this. --- .github/workflows/test-code-quality.yml | 3 ++ .../test_integration_suite_imports.py | 54 +++++++++++++++++++ tests/integration/_support/client.py | 2 +- tests/integration/_support/generation.py | 2 +- .../authorization/test_warmed_policy.py | 6 +-- .../configuration/test_effective_settings.py | 4 +- tests/integration/conftest.py | 6 +-- .../management/test_key_updates.py | 4 +- .../test_partial_update_sequences.py | 6 +-- .../pricing/test_configured_prices.py | 4 +- .../providers/test_request_boundary.py | 2 +- 11 files changed, 75 insertions(+), 18 deletions(-) create mode 100644 tests/code_coverage_tests/test_integration_suite_imports.py diff --git a/.github/workflows/test-code-quality.yml b/.github/workflows/test-code-quality.yml index 987f66773f2..58809e1ef29 100644 --- a/.github/workflows/test-code-quality.yml +++ b/.github/workflows/test-code-quality.yml @@ -83,6 +83,9 @@ jobs: - name: test_e2e_changed_gate run: uv run --no-sync pytest -q --noconftest -p no:cacheprovider -c /dev/null tests/code_coverage_tests/test_e2e_changed_gate.py tests/code_coverage_tests/test_e2e_idp_stack.py + - name: test_integration_suite_imports + run: uv run --no-sync pytest -q --noconftest -p no:cacheprovider -c /dev/null tests/code_coverage_tests/test_integration_suite_imports.py + - name: router_code_coverage run: uv run --no-sync python ./tests/code_coverage_tests/router_code_coverage.py diff --git a/tests/code_coverage_tests/test_integration_suite_imports.py b/tests/code_coverage_tests/test_integration_suite_imports.py new file mode 100644 index 00000000000..ed299e7ce5a --- /dev/null +++ b/tests/code_coverage_tests/test_integration_suite_imports.py @@ -0,0 +1,54 @@ +from __future__ import annotations + +import os +import re +import subprocess +import sys +from pathlib import Path +from typing import Final + +import pytest + +REPO_ROOT: Final = Path(__file__).resolve().parents[2] +INTEGRATION_ROOT: Final = REPO_ROOT / "tests" / "integration" +COLLECTED_COUNT: Final = re.compile(r"^(\d+) tests? collected", re.MULTILINE) + + +def _integration_test_files() -> tuple[Path, ...]: + return tuple(sorted(INTEGRATION_ROOT.rglob("test_*.py"))) + + +def _collect_without_injected_pythonpath(target: str) -> subprocess.CompletedProcess[str]: + env: Final = {key: value for key, value in os.environ.items() if key != "PYTHONPATH"} + return subprocess.run( + (sys.executable, "-m", "pytest", target, "--collect-only", "-q", "-p", "no:cacheprovider"), + cwd=REPO_ROOT, + env=env, + capture_output=True, + text=True, + check=False, + ) + + +def _assert_collected(result: subprocess.CompletedProcess[str], target: str) -> None: + assert result.returncode == 0, f"{target} exited {result.returncode}\n{result.stdout}\n{result.stderr}" + match: Final = COLLECTED_COUNT.search(result.stdout) + assert match is not None, f"{target} reported no collection summary\n{result.stdout}" + assert int(match.group(1)) > 0, f"{target} collected nothing, so nothing was verified\n{result.stdout}" + + +def test_the_integration_suite_still_has_files_to_guard() -> None: + assert _integration_test_files() + + +@pytest.mark.parametrize( + "target", + [str(path.relative_to(REPO_ROOT)) for path in _integration_test_files()], +) +def test_each_integration_file_collects_the_way_its_docs_document_it(target: str) -> None: + _assert_collected(_collect_without_injected_pythonpath(target), target) + + +def test_the_whole_integration_directory_collects_without_an_injected_pythonpath() -> None: + target: Final = "tests/integration" + _assert_collected(_collect_without_injected_pythonpath(target), target) diff --git a/tests/integration/_support/client.py b/tests/integration/_support/client.py index 8d6744c60a2..bfaec66eb3a 100644 --- a/tests/integration/_support/client.py +++ b/tests/integration/_support/client.py @@ -12,7 +12,7 @@ from typing import Final, TypeVar import httpx from pydantic import JsonValue, TypeAdapter -from integration._support.database import read_rows +from tests.integration._support.database import read_rows JSON_OBJECT: Final = TypeAdapter(dict[str, JsonValue]) T = TypeVar("T") diff --git a/tests/integration/_support/generation.py b/tests/integration/_support/generation.py index afb3ec2e768..50c1a6f2ad4 100644 --- a/tests/integration/_support/generation.py +++ b/tests/integration/_support/generation.py @@ -6,7 +6,7 @@ from contextlib import contextmanager import httpx from hypothesis import Phase, settings -from integration._support.client import Gateway +from tests.integration._support.client import Gateway LIFECYCLE_SETTINGS: Final = settings( max_examples=20, diff --git a/tests/integration/authorization/test_warmed_policy.py b/tests/integration/authorization/test_warmed_policy.py index fd4271dbc41..cc1f1eb3596 100644 --- a/tests/integration/authorization/test_warmed_policy.py +++ b/tests/integration/authorization/test_warmed_policy.py @@ -8,9 +8,9 @@ import pytest from hypothesis import strategies as st from hypothesis.stateful import RuleBasedStateMachine, invariant, rule, run_state_machine_as_test -from integration._support.client import Gateway, eventually, object_value -from integration._support.database import read_rows -from integration._support.generation import LIFECYCLE_SETTINGS, bounded_http_requests +from tests.integration._support.client import Gateway, eventually, object_value +from tests.integration._support.database import read_rows +from tests.integration._support.generation import LIFECYCLE_SETTINGS, bounded_http_requests def assert_serving(gateway: Gateway, model: str, key: str, status: int, error_type: str = "auth_error") -> None: diff --git a/tests/integration/configuration/test_effective_settings.py b/tests/integration/configuration/test_effective_settings.py index 7fa440d1d8d..8e164acbe03 100644 --- a/tests/integration/configuration/test_effective_settings.py +++ b/tests/integration/configuration/test_effective_settings.py @@ -4,8 +4,8 @@ from typing import Final import httpx import pytest -from integration._support.client import Gateway, object_value, string_value -from integration._support.database import read_rows +from tests.integration._support.client import Gateway, object_value, string_value +from tests.integration._support.database import read_rows def model_identity(gateway: Gateway, alias: str) -> str: diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index f5a018d305a..666b1dca348 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -11,9 +11,9 @@ import pytest import httpx from redis import Redis -from integration._support.client import Gateway, eventually, gateway_from_environment -from integration._support.manifest import OWNED_DIRECTORIES, contracts -from integration._support.generation import LIFECYCLE_SETTINGS +from tests.integration._support.client import Gateway, eventually, gateway_from_environment +from tests.integration._support.manifest import OWNED_DIRECTORIES, contracts +from tests.integration._support.generation import LIFECYCLE_SETTINGS COLLECTED: Final = pytest.StashKey[tuple[str, ...]]() REPORTS: Final = pytest.StashKey[list[pytest.TestReport]]() diff --git a/tests/integration/management/test_key_updates.py b/tests/integration/management/test_key_updates.py index 6f2e850b17a..b460190f0ba 100644 --- a/tests/integration/management/test_key_updates.py +++ b/tests/integration/management/test_key_updates.py @@ -3,8 +3,8 @@ from hashlib import sha256 import pytest -from integration._support.client import Gateway, object_value -from integration._support.database import read_rows +from tests.integration._support.client import Gateway, object_value +from tests.integration._support.database import read_rows @pytest.mark.covers("mgmt.key.update.preserves_independent_fields") diff --git a/tests/integration/management/test_partial_update_sequences.py b/tests/integration/management/test_partial_update_sequences.py index c645b896448..01412ccf11b 100644 --- a/tests/integration/management/test_partial_update_sequences.py +++ b/tests/integration/management/test_partial_update_sequences.py @@ -7,9 +7,9 @@ from hypothesis import strategies as st from hypothesis.stateful import RuleBasedStateMachine, invariant, rule, run_state_machine_as_test from pydantic import JsonValue -from integration._support.client import Gateway, object_value -from integration._support.database import read_rows -from integration._support.generation import LIFECYCLE_SETTINGS, bounded_http_requests +from tests.integration._support.client import Gateway, object_value +from tests.integration._support.database import read_rows +from tests.integration._support.generation import LIFECYCLE_SETTINGS, bounded_http_requests @pytest.mark.covers("mgmt.key.update.generated_sequences_preserve_state") diff --git a/tests/integration/pricing/test_configured_prices.py b/tests/integration/pricing/test_configured_prices.py index 151103f6df5..56f022b6bc5 100644 --- a/tests/integration/pricing/test_configured_prices.py +++ b/tests/integration/pricing/test_configured_prices.py @@ -6,8 +6,8 @@ import uuid import pytest import yaml -from integration._support.client import Gateway, eventually, object_value, string_value -from integration._support.database import read_rows +from tests.integration._support.client import Gateway, eventually, object_value, string_value +from tests.integration._support.database import read_rows @pytest.mark.covers("quota_management.spend_tracking.custom_price.matches_input_rates") diff --git a/tests/integration/providers/test_request_boundary.py b/tests/integration/providers/test_request_boundary.py index aad10843642..33663cd4c59 100644 --- a/tests/integration/providers/test_request_boundary.py +++ b/tests/integration/providers/test_request_boundary.py @@ -3,7 +3,7 @@ from typing import Final import httpx import pytest -from integration._support.client import Gateway, JSON_OBJECT, object_value +from tests.integration._support.client import Gateway, JSON_OBJECT, object_value @pytest.mark.covers("other.provider_wire.internal_parameters_filtered") From a1bf9487311a95708bf1b13cc79537cdd9f00fbe Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Tue, 15 Sep 2026 22:39:32 -0700 Subject: [PATCH 2/4] test: assert integration collection by summary, not exit code --- .../test_integration_suite_imports.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/code_coverage_tests/test_integration_suite_imports.py b/tests/code_coverage_tests/test_integration_suite_imports.py index ed299e7ce5a..9cf2c9be394 100644 --- a/tests/code_coverage_tests/test_integration_suite_imports.py +++ b/tests/code_coverage_tests/test_integration_suite_imports.py @@ -31,9 +31,14 @@ def _collect_without_injected_pythonpath(target: str) -> subprocess.CompletedPro def _assert_collected(result: subprocess.CompletedProcess[str], target: str) -> None: - assert result.returncode == 0, f"{target} exited {result.returncode}\n{result.stdout}\n{result.stderr}" + # The exit code cannot carry this: tests/integration/conftest.py raises a UsageError + # under GITHUB_ACTIONS to keep these contracts owned by CircleCI, so a healthy + # collection and a failed import both exit 4. Only the summary line separates them. match: Final = COLLECTED_COUNT.search(result.stdout) - assert match is not None, f"{target} reported no collection summary\n{result.stdout}" + assert match is not None, ( + f"{target} never reached a collection summary, so its imports did not resolve\n" + f"{result.stdout}\n{result.stderr}" + ) assert int(match.group(1)) > 0, f"{target} collected nothing, so nothing was verified\n{result.stdout}" From 3080ee80138b1f2bea5426daf13b8384ff3e5699 Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Tue, 15 Sep 2026 22:44:58 -0700 Subject: [PATCH 3/4] test: fail the integration gate on partial collection errors --- .../test_integration_suite_imports.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/code_coverage_tests/test_integration_suite_imports.py b/tests/code_coverage_tests/test_integration_suite_imports.py index 9cf2c9be394..246dffa6a5d 100644 --- a/tests/code_coverage_tests/test_integration_suite_imports.py +++ b/tests/code_coverage_tests/test_integration_suite_imports.py @@ -11,7 +11,9 @@ import pytest REPO_ROOT: Final = Path(__file__).resolve().parents[2] INTEGRATION_ROOT: Final = REPO_ROOT / "tests" / "integration" -COLLECTED_COUNT: Final = re.compile(r"^(\d+) tests? collected", re.MULTILINE) +COLLECTION_SUMMARY: Final = re.compile( + r"^(?P\d+) tests? collected(?:, (?P\d+) errors?)?", re.MULTILINE +) def _integration_test_files() -> tuple[Path, ...]: @@ -31,15 +33,20 @@ def _collect_without_injected_pythonpath(target: str) -> subprocess.CompletedPro def _assert_collected(result: subprocess.CompletedProcess[str], target: str) -> None: - # The exit code cannot carry this: tests/integration/conftest.py raises a UsageError - # under GITHUB_ACTIONS to keep these contracts owned by CircleCI, so a healthy - # collection and a failed import both exit 4. Only the summary line separates them. - match: Final = COLLECTED_COUNT.search(result.stdout) + # Both a healthy collection and a failed import exit 4 here, because conftest.py's + # CircleCI-ownership guard fires under GITHUB_ACTIONS; only the summary separates them. + match: Final = COLLECTION_SUMMARY.search(result.stdout) assert match is not None, ( f"{target} never reached a collection summary, so its imports did not resolve\n" f"{result.stdout}\n{result.stderr}" ) - assert int(match.group(1)) > 0, f"{target} collected nothing, so nothing was verified\n{result.stdout}" + assert int(match.group("collected")) > 0, ( + f"{target} collected nothing, so nothing was verified\n{result.stdout}" + ) + # One broken file among many still reports a count: "83 tests collected, 1 error". + assert match.group("errors") is None, ( + f"{target} reported {match.group('errors')} collection error(s)\n{result.stdout}\n{result.stderr}" + ) def test_the_integration_suite_still_has_files_to_guard() -> None: From 79cdcbf6c6332da36a7c2e8e61678fb201514cdc Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Tue, 15 Sep 2026 23:25:33 -0700 Subject: [PATCH 4/4] revert: drop the collection gate and keep the import fix --- .github/workflows/test-code-quality.yml | 3 - .../test_integration_suite_imports.py | 66 ------------------- 2 files changed, 69 deletions(-) delete mode 100644 tests/code_coverage_tests/test_integration_suite_imports.py diff --git a/.github/workflows/test-code-quality.yml b/.github/workflows/test-code-quality.yml index 58809e1ef29..987f66773f2 100644 --- a/.github/workflows/test-code-quality.yml +++ b/.github/workflows/test-code-quality.yml @@ -83,9 +83,6 @@ jobs: - name: test_e2e_changed_gate run: uv run --no-sync pytest -q --noconftest -p no:cacheprovider -c /dev/null tests/code_coverage_tests/test_e2e_changed_gate.py tests/code_coverage_tests/test_e2e_idp_stack.py - - name: test_integration_suite_imports - run: uv run --no-sync pytest -q --noconftest -p no:cacheprovider -c /dev/null tests/code_coverage_tests/test_integration_suite_imports.py - - name: router_code_coverage run: uv run --no-sync python ./tests/code_coverage_tests/router_code_coverage.py diff --git a/tests/code_coverage_tests/test_integration_suite_imports.py b/tests/code_coverage_tests/test_integration_suite_imports.py deleted file mode 100644 index 246dffa6a5d..00000000000 --- a/tests/code_coverage_tests/test_integration_suite_imports.py +++ /dev/null @@ -1,66 +0,0 @@ -from __future__ import annotations - -import os -import re -import subprocess -import sys -from pathlib import Path -from typing import Final - -import pytest - -REPO_ROOT: Final = Path(__file__).resolve().parents[2] -INTEGRATION_ROOT: Final = REPO_ROOT / "tests" / "integration" -COLLECTION_SUMMARY: Final = re.compile( - r"^(?P\d+) tests? collected(?:, (?P\d+) errors?)?", re.MULTILINE -) - - -def _integration_test_files() -> tuple[Path, ...]: - return tuple(sorted(INTEGRATION_ROOT.rglob("test_*.py"))) - - -def _collect_without_injected_pythonpath(target: str) -> subprocess.CompletedProcess[str]: - env: Final = {key: value for key, value in os.environ.items() if key != "PYTHONPATH"} - return subprocess.run( - (sys.executable, "-m", "pytest", target, "--collect-only", "-q", "-p", "no:cacheprovider"), - cwd=REPO_ROOT, - env=env, - capture_output=True, - text=True, - check=False, - ) - - -def _assert_collected(result: subprocess.CompletedProcess[str], target: str) -> None: - # Both a healthy collection and a failed import exit 4 here, because conftest.py's - # CircleCI-ownership guard fires under GITHUB_ACTIONS; only the summary separates them. - match: Final = COLLECTION_SUMMARY.search(result.stdout) - assert match is not None, ( - f"{target} never reached a collection summary, so its imports did not resolve\n" - f"{result.stdout}\n{result.stderr}" - ) - assert int(match.group("collected")) > 0, ( - f"{target} collected nothing, so nothing was verified\n{result.stdout}" - ) - # One broken file among many still reports a count: "83 tests collected, 1 error". - assert match.group("errors") is None, ( - f"{target} reported {match.group('errors')} collection error(s)\n{result.stdout}\n{result.stderr}" - ) - - -def test_the_integration_suite_still_has_files_to_guard() -> None: - assert _integration_test_files() - - -@pytest.mark.parametrize( - "target", - [str(path.relative_to(REPO_ROOT)) for path in _integration_test_files()], -) -def test_each_integration_file_collects_the_way_its_docs_document_it(target: str) -> None: - _assert_collected(_collect_without_injected_pythonpath(target), target) - - -def test_the_whole_integration_directory_collects_without_an_injected_pythonpath() -> None: - target: Final = "tests/integration" - _assert_collected(_collect_without_injected_pythonpath(target), target)