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.
0.35.0 - 2024-11-28
- Requires
httpx
==0.28.*
0.34.0 - 2024-11-18
is_optional
parameter 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_reusable
parameter 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_request
will 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_mock
option (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_files
andmatch_data
parameters. Refer to documentation for more details. - Matching on extensions (including timeout) can now be performed using
match_extensions
parameter. Refer to documentation for more details.
non_mocked_hosts
option is not available anymore. Useshould_mock
instead 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.TimeoutException
message 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.TimeoutException
message 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.TimeoutException
message 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.TimeoutException
message 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
HTTPXMock
class 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
HTTPXMockOptions
class was never intended to be exposed and is now marked as private.
0.31.2 - 2024-09-23
httpx_mock
marker 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_mock
fixture 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.reset
do not expect any parameter anymore and will only reset the mock state (no assertions will be performed).
pytest
7
is not supported anymore (pytest
8
has been out for 9 months already).assert_all_responses_were_requested
fixture is not available anymore, usepytest.mark.httpx_mock(assert_all_responses_were_requested=False)
instead.non_mocked_hosts
fixture 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.py
topyproject.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_request
orhandle_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_url
parameter which allows matching on proxy URL.
0.25.0 - 2023-09-11
- Requires
httpx
==0.25.*
pytest
6
is no longer supported.
0.24.0 - 2023-09-04
- Added
match_json
parameter 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_headers
parameter was not considering header names case when matching.- As this might have been considered a feature by some users, the fact that
match_headers
will 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
:Any
type hint to**matchers
function arguments to satisfy strict type checking mode inpyright
.
0.23.1 - 2023-08-02
- Version
0.23.0
introduced 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.7
and3.8
are no longer supported.
httpx_mock.add_response
is now returning a newhttpx.Response
instance 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
pytest
dependency to supportpackaging
23
. - Add explicit support for
python
3.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_callback
now handles async callbacks.
0.21.0 - 2022-05-24
- Requires
httpx
==0.23.*
- Python
3.6
is 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_response
data
,files
andboundary
parameters 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_exception
method.
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.elapsed
computing.
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.elapsed
computing.
0.17.0 - 2021-12-20
httpx_mock.add_response
data
parameter 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_response
function 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_response
data
,files
andboundary
parameters that were only used for multipart content. Instead, provide thestream
parameter 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.Response
instance instead of the previoushttpcore.Response
tuple. As a consequence,pytest_httpx.to_response
now returns ahttpx.Response
instance.
httpx_mock.add_response
now allows to explicitly provide bytes usingcontent
parameter.httpx_mock.add_response
now allows to explicitly provide string usingtext
parameter.httpx_mock.add_response
now allows to explicitly provide HTML string content usinghtml
parameter.httpx_mock.add_response
now allows to explicitly provide streamed content usingstream
parameter and the newpytest_httpx.IteratorStream
class.
pytest_httpx.to_response
is now deprecated in favor ofhttpx.Response
. This function will be removed in a future release.httpx_mock.add_response
data
parameter should now only be used for multipart content. Instead, use the appropriate parameter amongstcontent
,text
,html
orstream
.
0.13.0 - 2021-08-19
- Requires
httpx
==0.19.* files
parameter ofhttpx_mock.add_response
now expect dictionary values to be binary (as perhttpx
new requirement).
0.12.1 - 2021-08-11
0.12.0 - 2021-04-27
- Requires
httpx
==0.18.* ext
callback 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
. Viacontent
parameter instead ofdata
. - Code now follow
black==20.8b1
formatting instead of the git master version. - Sending a JSON response using
json
parameter will now set theapplication/json
content-type header by default.
- Allow to provide any supported
httpx
headers type in headers parameter forhttpx_mock.add_response
andpytest_httpx.to_response
. Previously only dict was supported.
0.9.0 - 2020-09-22
- Requires
httpx
==0.15.* - Callbacks are now called with
ext
dictionary instead oftimeout
. To followhttpcore
design changes. You can still retrieve timeout by usingext['timeout']
0.8.0 - 2020-08-26
non_mocked_hosts
fixture 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.HTTPError
message issued in case no mock could be found is now ahttpx.TimeoutException
containing 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
pytest
6. assert_and_reset
mock method has been renamed toreset
and 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_requested
fixture. Refer to documentation for more details.
- It is not possible to provide an URL encoded response anymore by providing a dictionary in
data
parameter.
0.4.0 - 2020-06-05
httpx_mock
pytest
fixture does not need to be explicitly imported anymore (many thanks toThomas LÉVEIL
).
0.3.0 - 2020-05-24
- Requires
httpx
==0.13.* - requires
pytest
5.4.0 (at least) - callbacks must now return a tuple as per
httpcore
specifications. Refer to documentation for more details. - callbacks timeout parameter is now a dict as per
httpcore
specifications.
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.HTTPError
is now raised instead ofException
in 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
httpx
requests 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.