Skip to content

Commit 4924896

Browse files
committed
Patch httpx_mock so it'll work with all versions
httpx_mock introcuced a change in version 0.31.0 where a reset parameter was moved to the the init of the fixture
1 parent 2449f58 commit 4924896

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/conftest.py

+17
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ def register_models(self, register):
139139
pm.unregister(name="undo-mock-models-plugin")
140140

141141

142+
@pytest.fixture(autouse=True)
143+
def fix_httpx_mock(httpx_mock):
144+
"""As of version 0.31.0 httpx_mock takes no arguments in reset method.
145+
https://github.com/Colin-b/pytest_httpx/blob/develop/CHANGELOG.md#0310
146+
"""
147+
org_reset = httpx_mock.reset
148+
149+
def better_reset(self, assert_all_responses_were_requested: bool = False):
150+
"""Reset the mock, regardless of httpx_mock version."""
151+
try:
152+
org_reset()
153+
except TypeError:
154+
org_reset(assert_all_responses_were_requested)
155+
156+
httpx_mock.reset = better_reset.__get__(httpx_mock)
157+
158+
142159
@pytest.fixture
143160
def mocked_openai_chat(httpx_mock):
144161
httpx_mock.add_response(

0 commit comments

Comments
 (0)