Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #252 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 366 368 +2
Branches 69 70 +1
=========================================
+ Hits 366 368 +2 ☔ View full report in Codecov by Harness. |
Colin-b
left a comment
There was a problem hiding this comment.
I am not sure about this, why would you even provide it as empty? The default behavior is to check the full URL with params included. So it covers it. The regex case look valid but again, this is user provided regex, so they should include the query parameters as well if this is what they want to assert
|
You're right that normal URL matching already checks the query parameters. My intent here was only to make configuration validation consistent: with no URL or a regex URL, I found this through code inspection rather than a real-world failing use case. Since this would make previously accepted configurations raise, consistency alone may not justify the change. Would you prefer to keep ignoring an empty dict in these cases? |
|
You are right, this might be misleading to some people, even if this is an edge case. Better be safe than sorry, I'm fine with the change |
Colin-b
left a comment
There was a problem hiding this comment.
Few comments and we also lack the same changes on the async test file
|
|
||
| ### Fixed | ||
| - `match_params` now preserves `unittest.mock.ANY` inside tuple values, as it already does for lists. | ||
| - Empty `match_params` now requires a non-regex URL, just like non-empty `match_params`. |
There was a problem hiding this comment.
| - Empty `match_params` now requires a non-regex URL, just like non-empty `match_params`. | |
| - Providing an empty `match_params` will now assert that no query parameters was provided. Note that you do not need to provide it if you already use the `url` parameter and this value does not contains query parameters. |
There was a problem hiding this comment.
Updated the changelog to describe the empty-query assertion, including when url is omitted, and to note that a concrete URL without query parameters already provides this behavior.
|
|
||
| @pytest.mark.httpx_mock(assert_all_requests_were_expected=False) | ||
| def test_empty_match_params_requires_no_query(httpx_mock: HTTPXMock) -> None: | ||
| httpx_mock.add_response(url="https://test_url", match_params={}, is_reusable=True) |
There was a problem hiding this comment.
| httpx_mock.add_response(url="https://test_url", match_params={}, is_reusable=True) | |
| httpx_mock.add_response(match_params={}, is_reusable=True) |
There was a problem hiding this comment.
With this change we actually test a more realistic use case of empty match_params
There was a problem hiding this comment.
Updated the test to omit url and added matching async coverage. I also adjusted the matcher so match_params={} is accepted without a URL and only matches requests without query parameters. The tests cover different URLs, query mismatches, the default None behavior, and invalid configurations. Non-empty match_params still requires a URL; combining match_params with a regex URL remains unsupported.
Local validation on Windows / Python 3.13.1: 359 tests passed with 100% coverage. Formatting, lint/type checks, the remaining configured hooks, and sdist/wheel builds also passed.
|



An empty
match_paramsdictionary bypasses the URL validation because the checks use truthiness. With no URL or with a regex URL, those parameters are then silently ignored.Check whether
match_paramswas supplied (is not None) so empty and non-empty dictionaries follow the same validation. Extend both invalid-configuration tests and verify that a concrete URL with{}still matches only requests without query parameters. Add an Unreleased changelog entry.Validation on Windows / Python 3.13.1:
pytest -q --cov-report=term-missingin a dedicated editable-install environment: 349 passed, 100% coverage.Prepared with OpenAI Codex assistance.