Skip to content

Commit eface88

Browse files
lesnik512claude
andcommitted
test: exclude pytest.fail() lines from coverage via pyproject
pytest.fail(...) marks a branch that must never execute, so exclude it globally in coverage.report.exclude_also instead of per-line pragmas. Drops the # pragma: no cover comments added for the bounded-stream tests, and strengthens the whitespace-padded-key redaction test to assert the masked form. Pre-existing pragmas elsewhere are now redundant and can be swept separately. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8c23503 commit eface88

4 files changed

Lines changed: 8 additions & 7 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@ asyncio_default_fixture_loop_scope = "function"
9797

9898
[tool.coverage]
9999
run.concurrency = ["thread"]
100-
report.exclude_also = ["if typing.TYPE_CHECKING:"]
100+
report.exclude_also = ["if typing.TYPE_CHECKING:", 'pytest\.fail\(']

tests/test_client_stream.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def handler(request: httpx2.Request) -> httpx2.Response: # noqa: ARG001
351351
)
352352
with pytest.raises(ResponseTooLargeError) as caught:
353353
async with client.stream("GET", "https://example.test/x"):
354-
pytest.fail("unreachable") # pragma: no cover
354+
pytest.fail("unreachable")
355355
assert caught.value.limit == 10 # noqa: PLR2004 — mirrors max_error_body_bytes above
356356
assert caught.value.content_length == 200 # noqa: PLR2004 — len(body) above
357357
await client.aclose()
@@ -368,7 +368,7 @@ def handler(request: httpx2.Request) -> httpx2.Response: # noqa: ARG001
368368
)
369369
with pytest.raises(NotFoundError) as caught:
370370
async with client.stream("GET", "https://example.test/x"):
371-
pytest.fail("unreachable") # pragma: no cover
371+
pytest.fail("unreachable")
372372
assert caught.value.response.content == body
373373
await client.aclose()
374374

@@ -382,7 +382,7 @@ def handler(request: httpx2.Request) -> httpx2.Response: # noqa: ARG001
382382
client = AsyncClient(httpx2_client=httpx2.AsyncClient(transport=httpx2.MockTransport(handler)))
383383
with pytest.raises(InternalServerError) as caught:
384384
async with client.stream("GET", "https://example.test/x"):
385-
pytest.fail("unreachable") # pragma: no cover
385+
pytest.fail("unreachable")
386386
assert caught.value.response.content == body
387387
await client.aclose()
388388

tests/test_client_stream_sync.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def handler(request: httpx2.Request) -> httpx2.Response: # noqa: ARG001
316316

317317
client = Client(httpx2_client=httpx2.Client(transport=httpx2.MockTransport(handler)), max_error_body_bytes=10)
318318
with pytest.raises(ResponseTooLargeError) as caught, client.stream("GET", "https://example.test/x"):
319-
pytest.fail("unreachable") # pragma: no cover
319+
pytest.fail("unreachable")
320320
assert caught.value.limit == 10 # noqa: PLR2004 — mirrors max_error_body_bytes above
321321
assert caught.value.content_length == 200 # noqa: PLR2004 — len(body) above
322322
client.close()
@@ -330,7 +330,7 @@ def handler(request: httpx2.Request) -> httpx2.Response: # noqa: ARG001
330330

331331
client = Client(httpx2_client=httpx2.Client(transport=httpx2.MockTransport(handler)), max_error_body_bytes=1000)
332332
with pytest.raises(NotFoundError) as caught, client.stream("GET", "https://example.test/x"):
333-
pytest.fail("unreachable") # pragma: no cover
333+
pytest.fail("unreachable")
334334
assert caught.value.response.content == body
335335
client.close()
336336

@@ -343,6 +343,6 @@ def handler(request: httpx2.Request) -> httpx2.Response: # noqa: ARG001
343343

344344
client = Client(httpx2_client=httpx2.Client(transport=httpx2.MockTransport(handler)))
345345
with pytest.raises(InternalServerError) as caught, client.stream("GET", "https://example.test/x"):
346-
pytest.fail("unreachable") # pragma: no cover
346+
pytest.fail("unreachable")
347347
assert caught.value.response.content == body
348348
client.close()

tests/test_redaction.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ def test_redact_url_masks_whitespace_padded_key() -> None:
5757
# a space-padded sensitive key name must still be masked
5858
result = redact_url("https://example.test/p?%20api_key=topsecret")
5959
assert "topsecret" not in result
60+
assert "REDACTED" in result

0 commit comments

Comments
 (0)