All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
match_paramsparameter is now available on responses and callbacks registration, as well as request(s) retrieval. Allowing to provide query parameters as a dict instead of being part of the matched URL.- This parameter allows to perform partial query params matching (refer to documentation for more information).
- URL with more than one value for the same parameter were not matched properly (matching was performed on the first value).
0.35.0 - 2024-11-28
- Requires
httpx==0.28.*
0.34.0 - 2024-11-18
is_optionalparameter is now available on responses and callbacks registration. Allowing to add optional responses while keeping other responses as mandatory. Refer to documentation for more details.is_reusableparameter is now available on responses and callbacks registration. Allowing to add multi-match responses while keeping other responses as single-match. Refer to documentation for more details.
httpx_mock.get_requestwill now also propose to refine filters if more than one request is found instead of only proposing to switch tohttpx_mock.get_requests.
0.33.0 - 2024-10-28
- Explicit support for python
3.13. should_mockoption (callable returning a boolean) is now available, defaulting to always returningTrue. Refer to documentation for more details.- Matching on the full multipart body can now be performed using
match_filesandmatch_dataparameters. Refer to documentation for more details. - Matching on extensions (including timeout) can now be performed using
match_extensionsparameter. Refer to documentation for more details.
non_mocked_hostsoption is not available anymore. Useshould_mockinstead as in the following sample:Please note that your hosts might need to be prefixed withimport pytest @pytest.mark.httpx_mock(non_mocked_hosts=["my_local_test_host"]) def test_previous_behavior(httpx_mock): ... @pytest.mark.httpx_mock(should_mock=lambda request: request.url.host not in ["my_local_test_host"]) def test_new_behavior(httpx_mock): ...
www.depending on your usage.
0.32.0 - 2024-09-27
- The following option is now available:
can_send_already_matched_responses(boolean), defaulting toFalse.
- Assertion failure message in case of unmatched responses is now linking documentation on how to deactivate the check.
- Assertion failure message in case of unmatched requests is now linking documentation on how to deactivate the check.
httpx.TimeoutExceptionmessage issued in case of unmatched request is now linking documentation on how to reuse responses (in case some responses are already matched).
- Documentation now clearly state the risks associated with changing the default options.
- Assertion failure message in case of unmatched requests at teardown is now describing requests in a more user-friendly way.
- Assertion failure message in case of unmatched requests at teardown is now prefixing requests with
-to highlight the fact that this is a list, preventing misapprehension in case only one element exists. - Assertion failure message in case of unmatched responses at teardown is now prefixing responses with
-to highlight the fact that this is a list, preventing misapprehension in case only one element exists. httpx.TimeoutExceptionmessage issued in case of unmatched request is now prefixing available responses with-to highlight the fact that this is a list, preventing misapprehension in case only one element exists.httpx.TimeoutExceptionmessage issued in case of unmatched request is now listing unmatched responses (in registration order) before already matched one (still in registration order).- The incentive behind this change is to help identify a potential mismatch faster as the first unmatched response is the most likely to be the one expected to match.
- Response description in failure messages (
httpx.TimeoutExceptionmessage issued in case of unmatched request or assertion failure message in case of unmatched responses at teardown) is now displaying if the response was already matched or not and less misleading in it's phrasing about what it can match (a single request by default).
- Last registered matching response will not be reused by default anymore in case all matching responses have already been sent.
- This behavior can be changed thanks to the new
pytest.mark.httpx_mock(can_send_already_matched_responses=True)option. - The incentive behind this change is to spot regression if a request was issued more than the expected number of times.
- This behavior can be changed thanks to the new
HTTPXMockclass was only exposed for type hinting purpose. This is now explained in the class docstring.- As a result this is the last time a change to
__init__signature will be documented and considered a breaking change. - Future changes will not be documented and will be considered as internal refactoring not worth a version bump.
__init__now expects one parameter, the newly introduced (since 0.31.0) options.
- As a result this is the last time a change to
HTTPXMockOptionsclass was never intended to be exposed and is now marked as private.
0.31.2 - 2024-09-23
httpx_mockmarker can now be defined at different levels for a single test.
0.31.1 - 2024-09-22
- It is now possible to match on content provided as async iterable by the client.
0.31.0 - 2024-09-20
- Tests will now fail at teardown by default if some requests were issued but were not matched.
- This behavior can be changed thanks to the new
pytest.mark.httpx_mock(assert_all_requests_were_expected=False)option. - The incentive behind this change is to spot unexpected requests in case code is swallowing
httpx.TimeoutException.
- This behavior can be changed thanks to the new
- The
httpx_mockfixture is now configured using a marker (many thanks toFrazer McLean).# Apply marker to whole module pytestmark = pytest.mark.httpx_mock(assert_all_responses_were_requested=False) # Or to specific tests @pytest.mark.httpx_mock(non_mocked_hosts=[...]) def test_foo(httpx_mock): ...
- The following options are available:
assert_all_responses_were_requested(boolean), defaulting toTrue.assert_all_requests_were_expected(boolean), defaulting toTrue.non_mocked_hosts(iterable), defaulting to an empty list, meaning all hosts are mocked.
- The following options are available:
httpx_mock.resetdo not expect any parameter anymore and will only reset the mock state (no assertions will be performed).
pytest7is not supported anymore (pytest8has been out for 9 months already).assert_all_responses_were_requestedfixture is not available anymore, usepytest.mark.httpx_mock(assert_all_responses_were_requested=False)instead.non_mocked_hostsfixture is not available anymore, usepytest.mark.httpx_mock(non_mocked_hosts=[])instead.
0.30.0 - 2024-02-21
- Requires
httpx==0.27.*
- Switch from
setup.pytopyproject.toml(many thanks toFelix Scherz).
0.29.0 - 2024-01-29
- Add support for
pytest==8.* (pytest==7.* is still supported for now) (many thanks toYossi Rozantsev).
0.28.0 - 2023-12-21
- Requires
httpx==0.26.*
0.27.0 - 2023-11-13
- Explicit support for python
3.12.
- Custom HTTP transport are now handled (parent call to
handle_async_requestorhandle_request).
- Only HTTP transport are now mocked, this should not have any impact, however if it does, please feel free to open an issue describing your use case.
0.26.0 - 2023-09-18
- Added
proxy_urlparameter which allows matching on proxy URL.
0.25.0 - 2023-09-11
- Requires
httpx==0.25.*
pytest6is no longer supported.
0.24.0 - 2023-09-04
- Added
match_jsonparameter which allows matching on JSON decoded body (matching against python representation instead of bytes).
- Even if it was never documented as a feature, the
match_headersparameter was not considering header names case when matching.- As this might have been considered a feature by some users, the fact that
match_headerswill now respect casing is documented as a breaking change.
- As this might have been considered a feature by some users, the fact that
- Matching on headers does not ignore name case anymore, the name must now be cased as sent (as some servers might expect a specific case).
- Error message in case a request does not match will now include request headers with mismatching name case as well.
- Error message in case a request does not match will now include request headers when not provided as lower-cased to
match_headers. - Add
:Anytype hint to**matchersfunction arguments to satisfy strict type checking mode inpyright.
0.23.1 - 2023-08-02
- Version
0.23.0introduced a regression removing the support for mutating json content provided inhttpx_mock.add_response.- This is fixed, you can now expect the JSON return being as it was when provided to
httpx_mock.add_response:
- This is fixed, you can now expect the JSON return being as it was when provided to
mutating_json = {"content": "request 1"}
# This will return {"content": "request 1"}
httpx_mock.add_response(json=mutating_json)
mutating_json["content"] = "request 2"
# This will return {"content": "request 2"}
httpx_mock.add_response(json=mutating_json)0.23.0 - 2023-08-02
- Python
3.7and3.8are no longer supported.
httpx_mock.add_responseis now returning a newhttpx.Responseinstance upon each matching request. Preventing unnecessary recursion in streams.
0.22.0 - 2023-04-12
- Requires
httpx==0.24.*
0.21.3 - 2023-01-20
- Update version specifiers for
pytestdependency to supportpackaging23. - Add explicit support for
python3.11.
0.21.2 - 2022-11-03
- URL containing non ASCII characters in query can now be matched.
- Requests are now cleared when calling
httpx_mock.reset.
0.21.1 - 2022-10-20
httpx_mock.add_callbacknow handles async callbacks.
0.21.0 - 2022-05-24
- Requires
httpx==0.23.*
- Python
3.6is no longer supported.
0.20.0 - 2022-02-05
- Add support for
pytest==7.* (pytest==6.* is still supported for now) (many thanks toCraig Blaszczyk).
0.19.0 - 2022-01-26
- Requires
httpx==0.22.*
- Python 3.6 is no longer supported.
0.18.0 - 2022-01-17
- Callback are now executed as expected when there is a matching already sent response.
- Registration order is now looking at responses and callbacks. Prior to this version, registration order was looking at responses before callbacks.
httpx_mock.add_responsedata,filesandboundaryparameters have been removed. It was deprecated since0.17.0. Refer to this version changelog entry for more details on how to update your code.
0.17.3 - 2021-12-27
- A callback can now raise an exception again (regression in mypy check since 0.16.0).
- An exception can now be raised without creating a callback by using
httpx_mock.add_exceptionmethod.
0.17.2 - 2021-12-23
- Do not consider a callback response as read, even if it is not a stream, before returning to
httpx. Allowing any specific httpx handling to be triggered such ashttpx.Response.elapsedcomputing.
0.17.1 - 2021-12-20
- Do not consider a response as read, even if it is not a stream, before returning to
httpx. Allowing any specific httpx handling to be triggered such ashttpx.Response.elapsedcomputing.
0.17.0 - 2021-12-20
httpx_mock.add_responsedataparameter is only used for multipart content. It was deprecated since0.14.0. Refer to this version changelog entry for more details on how to update your code.
pytest_httpx.to_responsefunction has been removed. It was deprecated since0.14.0. Refer to this version changelog entry for more details on how to update your code.
httpx_mock.add_responsedata,filesandboundaryparameters that were only used for multipart content. Instead, provide thestreamparameter with an instance of thehttpx._multipart.MultipartStream.
- Responses are no more read or closed when returned to the client. Allowing to add a response once and reading it as a new response on every request.
0.16.0 - 2021-12-20
- Callbacks are now expected to have a single parameter, the request. The previously second parameter
extensions, can still be accessed viarequest.extensions.
- Allow for users to run
mypy --strict.
0.15.0 - 2021-11-16
- Requires
httpx==0.21.*
0.14.0 - 2021-10-22
- Requires
httpx==0.20.* (many thanks toTerence Honles) - Callbacks are now expected to return a
httpx.Responseinstance instead of the previoushttpcore.Responsetuple. As a consequence,pytest_httpx.to_responsenow returns ahttpx.Responseinstance.
httpx_mock.add_responsenow allows to explicitly provide bytes usingcontentparameter.httpx_mock.add_responsenow allows to explicitly provide string usingtextparameter.httpx_mock.add_responsenow allows to explicitly provide HTML string content usinghtmlparameter.httpx_mock.add_responsenow allows to explicitly provide streamed content usingstreamparameter and the newpytest_httpx.IteratorStreamclass.
pytest_httpx.to_responseis now deprecated in favor ofhttpx.Response. This function will be removed in a future release.httpx_mock.add_responsedataparameter should now only be used for multipart content. Instead, use the appropriate parameter amongstcontent,text,htmlorstream.
0.13.0 - 2021-08-19
- Requires
httpx==0.19.* filesparameter ofhttpx_mock.add_responsenow expect dictionary values to be binary (as perhttpxnew requirement).
0.12.1 - 2021-08-11
0.12.0 - 2021-04-27
- Requires
httpx==0.18.* extcallback parameter was renamed intoextensions.
0.11.0 - 2021-03-01
- Requires
httpx==0.17.*
0.10.1 - 2020-11-25
- Order of different parameters does not matter anymore for URL matching. It does however still matter for a same parameter.
0.10.0 - 2020-10-06
- Document how to assert that no requests were issued.
- Document how to send cookies.
- Explicit support for python 3.9
- Requires
httpx==0.16.* - Update documentation to reflect the latest way of sending bytes using
httpx. Viacontentparameter instead ofdata. - Code now follow
black==20.8b1formatting instead of the git master version. - Sending a JSON response using
jsonparameter will now set theapplication/jsoncontent-type header by default.
- Allow to provide any supported
httpxheaders type in headers parameter forhttpx_mock.add_responseandpytest_httpx.to_response. Previously only dict was supported.
0.9.0 - 2020-09-22
- Requires
httpx==0.15.* - Callbacks are now called with
extdictionary instead oftimeout. To followhttpcoredesign changes. You can still retrieve timeout by usingext['timeout']
0.8.0 - 2020-08-26
non_mocked_hostsfixture allowing to avoid mocking requests sent on some specific hosts.
- Display the matchers that were not matched instead of the responses that were not sent.
0.7.0 - 2020-08-13
- The
httpx.HTTPErrormessage issued in case no mock could be found is now ahttpx.TimeoutExceptioncontaining all information required to fix the test case (if needed).
0.6.0 - 2020-08-07
- Requires
httpx==0.14.*
0.5.0 - 2020-07-31
- requires
pytest6. assert_and_resetmock method has been renamed toresetand now takes a boolean parameter to specify if assertion should be performed.
- It is now possible to disable the assertion that all registered responses were requested thanks to the
assert_all_responses_were_requestedfixture. Refer to documentation for more details.
- It is not possible to provide an URL encoded response anymore by providing a dictionary in
dataparameter.
0.4.0 - 2020-06-05
httpx_mockpytestfixture does not need to be explicitly imported anymore (many thanks toThomas LÉVEIL).
0.3.0 - 2020-05-24
- Requires
httpx==0.13.* - requires
pytest5.4.0 (at least) - callbacks must now return a tuple as per
httpcorespecifications. Refer to documentation for more details. - callbacks timeout parameter is now a dict as per
httpcorespecifications.
0.2.1 - 2020-03-20
- Handle the fact that some classes and functions we use are now part of internals within
httpx.
0.2.0 - 2020-03-09
- Requires
httpx==0.12.*
0.1.0 - 2020-02-13
- Consider as stable.
0.0.5 - 2020-02-10
- match_headers parameter now allows matching on headers.
- match_content parameter now allows matching on full body.
httpx.HTTPErroris now raised instead ofExceptionin case a request cannot be matched.
0.0.4 - 2020-02-07
- url is not a mandatory parameter for response registration anymore.
- url is not a mandatory parameter for callback registration anymore.
- url is not a mandatory parameter for request retrieval anymore.
- method does not have a default value for response registration anymore.
- method does not have a default value for callback registration anymore.
- method does not have a default value for request retrieval anymore.
- url and methods are not positional arguments anymore.
0.0.3 - 2020-02-06
- Allow providing JSON response as python values.
- Mock async
httpxrequests as well. - Allow providing files and boundary for multipart response.
- Allow to provide data as a dictionary for multipart response.
- Allow providing callbacks that are executed upon reception of a request.
- Handle the fact that parameters may be introduced in
httpx*Dispatcher.send method. - Allow to retrieve all matching requests with HTTPXMock.get_requests
- method can now be provided even if not entirely upper-cased.
- content parameter renamed into data.
- HTTPXMock.get_request now fails if more than one request match. Use HTTPXMock.get_request instead.
- HTTPXMock.requests is now private, use HTTPXMock.get_requests instead.
- HTTPXMock.responses is now private, it should not be accessed anyway.
- url can now be a re.Pattern instance.
0.0.2 - 2020-02-06
- Allow to retrieve requests.
0.0.1 - 2020-02-05
- First release, should be considered as unstable for now as design might change.