MCPcopy
hub / github.com/openai/openai-python / test_overwrite_retry_count_header

Method test_overwrite_retry_count_header

tests/test_client.py:1217–1244  ·  tests/test_client.py::TestOpenAI.test_overwrite_retry_count_header
(
        self, client: OpenAI, failures_before_success: int, respx_mock: MockRouter
    )

Source from the content-addressed store, hash-verified

1215 @mock.patch(class="st">"openai._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
1216 @pytest.mark.respx(base_url=base_url)
1217 def test_overwrite_retry_count_header(
1218 self, client: OpenAI, failures_before_success: int, respx_mock: MockRouter
1219 ) -> None:
1220 client = client.with_options(max_retries=4)
1221
1222 nb_retries = 0
1223
1224 def retry_handler(_request: httpx.Request) -> httpx.Response:
1225 nonlocal nb_retries
1226 if nb_retries < failures_before_success:
1227 nb_retries += 1
1228 return httpx.Response(500)
1229 return httpx.Response(200)
1230
1231 respx_mock.post(class="st">"/chat/completions").mock(side_effect=retry_handler)
1232
1233 response = client.chat.completions.with_raw_response.create(
1234 messages=[
1235 {
1236 class="st">"content": class="st">"string",
1237 class="st">"role": class="st">"developer",
1238 }
1239 ],
1240 model=class="st">"gpt-5.4",
1241 extra_headers={class="st">"x-stainless-retry-count": class="st">"42"},
1242 )
1243
1244 assert response.http_request.headers.get(class="st">"x-stainless-retry-count") == class="st">"42"
1245
1246 @pytest.mark.parametrize(class="st">"failures_before_success", [0, 2, 4])
1247 @mock.patch(class="st">"openai._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)

Callers

nothing calls this directly

Calls 3

postMethod · 0.45
createMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected