Skip to content

Require matching request extensions to be present - #271

Open
Muneer320 wants to merge 1 commit into
Colin-b:developfrom
Muneer320:fix/missing-extension-match
Open

Muneer320 wants to merge 1 commit into
Colin-b:developfrom
Muneer320:fix/missing-extension-match

Conversation

@Muneer320

Copy link
Copy Markdown

match_extensions={"custom": None} currently accepts a request without a custom extension. The same false positive affects get_requests().

Require the extension key to be present before comparing its value. An explicitly present None still matches. Wildcard values such as unittest.mock.ANY also require the named extension to be present. This includes sync and async regression tests, a request-retrieval test and a changelog entry.

Public fixture reproducer on the original code:

import httpx
import pytest
from pytest_httpx import HTTPXMock


@pytest.mark.httpx_mock(assert_all_requests_were_expected=False)
def test_missing_extension(httpx_mock: HTTPXMock) -> None:
    httpx_mock.add_response(match_extensions={"custom": None}, is_optional=True)
    with httpx.Client() as client:
        with pytest.raises(httpx.TimeoutException):
            client.get("https://example.com")

The original code fails with DID NOT RAISE TimeoutException; the fix passes.

Validation on Windows / Python 3.13.7:

  • Original implementation: four checks fail, three explicit-None controls pass.
  • Fixed standalone public reproduction: both tests pass.
  • All 359 tests pass across three sequential module runs, with 100% combined statement and branch coverage. The separate coverage report --fail-under=100 gate passes.
  • All configured pre-commit hooks pass.
  • Other Python versions and operating systems have not been run locally.

@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant