Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)
Python
Make provider retry tests deterministic (#1070)
Ali Khokharf2f5b08714c4
diff --git a/tests/providers/support.py b/tests/providers/support.pyindex 5cdaf4c4..1f3266cc 100644--- a/tests/providers/support.py+++ b/tests/providers/support.py@@ -31,6 +31,23 @@ class PassthroughProviderRateLimiter(ProviderRateLimiter):return await fn(*args, **kwargs)+class ImmediateRetryProviderRateLimiter(ProviderRateLimiter):+ """Run the real retry policy without exercising wall-clock backoff."""++ async def execute_with_retry(+ self,+ fn: Callable[..., Any],+ *args: Any,+ **kwargs: Any,+ ) -> Any:+ kwargs.update(base_delay=0.0, max_delay=0.0, jitter=0.0)+ return await super().execute_with_retry(fn, *args, **kwargs)++ def extend_reactive_block(self, seconds: float) -> None:+ """Leave reactive timing to the limiter's dedicated unit tests."""+ del seconds++def passthrough_rate_limiter() -> ProviderRateLimiter:"""Return a fresh limiter test double for one provider instance."""return PassthroughProviderRateLimiter()@@ -51,8 +68,8 @@ def profiled_provider(def retrying_rate_limiter() -> ProviderRateLimiter:- """Return a fresh real limiter for provider retry-policy tests."""- return ProviderRateLimiter(+ """Return a limiter that exercises retry policy without elapsed time."""+ return ImmediateRetryProviderRateLimiter(rate_limit=1_000_000,rate_window=1.0,max_concurrency=1_000,diff --git a/tests/providers/test_openai_compat_5xx_retry.py b/tests/providers/test_openai_compat_5xx_retry.pyindex dfb62d57..af8fff00 100644--- a/tests/providers/test_openai_compat_5xx_retry.py+++ b/tests/providers/test_openai_compat_5xx_retry.py@@ -68,7 +68,6 @@ async def test_nim_stream_retries_on_openai_5xx_then_streams(status_code):"create",new_callable=AsyncMock,) as mock_create,- patch("asyncio.sleep", new_callable=AsyncMock),):mock_create.side_effect = [_internal_5xx(status_code), mock_stream()]events = [e async for e in provider.stream_response(req)]@@ -113,7 +112,6 @@ async def test_nim_stream_retries_on_pre_stream_connection_error_then_streams():"create",new_callable=AsyncMock,) as mock_create,- patch("asyncio.sleep", new_callable=AsyncMock),):mock_create.side_effect = [_connection_error(), mock_stream()]events = [e async for e in provider.stream_response(req)]@@ -148,7 +146,6 @@ async def test_nim_stream_connection_error_exhausted_emits_cause_chain():new_callable=AsyncMock,side_effect=error,) as mock_create,- patch("asyncio.sleep", new_callable=AsyncMock),patch("free_claude_code.providers.openai_chat.provider.trace_event") as trace,pytest.raises(ExecutionFailure) as exc_info,):@@ -202,7 +199,6 @@ async def test_nim_stream_openai_5xx_exhausted_emits_user_message("create",new_callable=AsyncMock,) as mock_create,- patch("asyncio.sleep", new_callable=AsyncMock),):mock_create.side_effect = _internal_5xx(status_code)with pytest.raises(ExecutionFailure) as exc_info: