The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(tests): resolve the integration support package without run.py's PYTHONPATH
Yuneng Jiang3b0fbc426d2f
diff --git a/.github/workflows/test-code-quality.yml b/.github/workflows/test-code-quality.ymlindex 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_gaterun: 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_coveragerun: uv run --no-sync python ./tests/code_coverage_tests/router_code_coverage.pydiff --git a/tests/code_coverage_tests/test_integration_suite_imports.py b/tests/code_coverage_tests/test_integration_suite_imports.pynew file mode 100644index 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()+++ "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.pyindex 8d6744c60a2..bfaec66eb3a 100644--- a/tests/integration/_support/client.py+++ b/tests/integration/_support/client.py@@ -12,7 +12,7 @@ from typing import Final, TypeVarimport httpxfrom pydantic import JsonValue, TypeAdapter-from integration._support.database import read_rows+from tests.integration._support.database import read_rowsJSON_OBJECT: Final = TypeAdapter(dict[str, JsonValue])T = TypeVar("T")diff --git a/tests/integration/_support/generation.py b/tests/integration/_support/generation.pyindex afb3ec2e768..50c1a6f2ad4 100644--- a/tests/integration/_support/generation.py+++ b/tests/integration/_support/generation.py@@ -6,7 +6,7 @@ from contextlib import contextmanagerimport httpxfrom hypothesis import Phase, settings-from integration._support.client import Gateway+from tests.integration._support.client import GatewayLIFECYCLE_SETTINGS: Final = settings(max_examples=20,diff --git a/tests/integration/authorization/test_warmed_policy.py b/tests/integration/authorization/test_warmed_policy.pyindex fd4271dbc41..cc1f1eb3596 100644--- a/tests/integration/authorization/test_warmed_policy.py+++ b/tests/integration/authorization/test_warmed_policy.py@@ -8,9 +8,9 @@ import pytestfrom hypothesis import strategies as stfrom 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_requestsdef 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.pyindex 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 Finalimport httpximport 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_rowsdef model_identity(gateway: Gateway, alias: str) -> str:diff --git a/tests/integration/conftest.py b/tests/integration/conftest.pyindex f5a018d305a..666b1dca348 100644--- a/tests/integration/conftest.py+++ b/tests/integration/conftest.py@@ -11,9 +11,9 @@ import pytestimport httpxfrom 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_SETTINGSCOLLECTED: 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.pyindex 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 sha256import 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.pyindex 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 stfrom hypothesis.stateful import RuleBasedStateMachine, invariant, rule, run_state_machine_as_testfrom 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.pyindex 151103f6df5..56f022b6bc5 100644--- a/tests/integration/pricing/test_configured_prices.py+++ b/tests/integration/pricing/test_configured_prices.py@@ -6,8 +6,8 @@ import uuidimport pytestimport 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.pyindex 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 Finalimport httpximport 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")