Skip to content

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]

tests(vcr): opt out tests that observe live cross-call provider state

mateo-berri8c01b027797a
diff --git a/tests/llm_translation/conftest.py b/tests/llm_translation/conftest.py
index 79e60117c97..540518124dc 100644
--- a/tests/llm_translation/conftest.py
+++ b/tests/llm_translation/conftest.py
@@ -47,6 +47,38 @@ _VCR_AUTO_MARKER_SKIP_FILES = _RESPX_CONFLICTING_FILES | frozenset(
{"test_vcr_redis_persister.py"}
)
+# Tests that observe live cross-call provider state (e.g. prompt-cache
+# warm-up between two consecutive calls) cannot benefit from cassette
+# replay: the second call's "expected" state depends on what the *live*
+# provider does between the two calls, not on what was recorded earlier.
+# Auto-marking them with @pytest.mark.vcr just wastes cycles and (before
+# the outcome gate) used to poison the cache. They go live with their
+# existing @pytest.mark.flaky retry logic.
+#
+# Match by suffix on the pytest nodeid so subclassed/parametrized variants
+# are covered: e.g. "::test_prompt_caching" matches all subclasses that
+# inherit the base test.
+_VCR_INCOMPATIBLE_NODEID_SUFFIXES = frozenset(
+ {
+ # Provider prompt-cache propagation isn't deterministic between two
+ # back-to-back calls; the test is flaky against the live provider.
+ "::test_prompt_caching",
+ # Wikipedia URL fetch through Anthropic Files API is flaky upstream.
+ "::test_async_pdf_handling_with_file_id",
+ # Bedrock Nova returns tool_call vs JSON nondeterministically; the
+ # base assertion expects JSON. Other providers' versions of this
+ # test are healthy, so we narrow with a class-name guard below.
+ "TestBedrockInvokeNovaJson::test_json_response_pydantic_obj",
+ # Bedrock streaming response_cost calc returns None intermittently.
+ "::test_bedrock_converse__streaming_passthrough",
+ }
+)
+
+
+def _is_vcr_incompatible(nodeid: str) -> bool:
+ return any(nodeid.endswith(suffix) for suffix in _VCR_INCOMPATIBLE_NODEID_SUFFIXES)
+
+
_FILTERED_REQUEST_HEADERS = (
"authorization",
"x-api-key",
@@ -255,6 +287,8 @@ def pytest_collection_modifyitems(config, items):
filename = os.path.basename(str(item.fspath))
if filename in _VCR_AUTO_MARKER_SKIP_FILES:
continue
+ if _is_vcr_incompatible(item.nodeid):
+ continue
if item.get_closest_marker("vcr") is not None:
continue
item.add_marker(pytest.mark.vcr)