Add a way to reset HTTPXMock._requests
Closed this issue · 2 comments
Normale commented
I started using httpx_mock and tried to mock multiple requests to one resource.
Then I expected httpx_mock.reset() to reset the state of HTTPXMock. However, it resets only callbacks, self._requests are still left unchanged.
Generally:
def test_something(httpx_mock: HTTPXMock):
# custom setup that has to be here, but includes mocked requests
httpx_mock.reset()
for i in range(5):
httpx.request(...)
assert len(httpx_mock.get_requests()) == 5 # fails, because of the mocked requests in "setup" part. There is no way to reset list of requests
Is there a reason why .reset() is not resetting requests list?
Colin-b commented
Hi @Normale ,
I guess it wouldnt hurt to reset the requests list as well indeed. I'm trying to see if it would cause a regression for some but I don't think it would.
Feel free to come up with a PR for this, in the meantime you can save the length right after reset (or before), and assert the difference.
Colin-b commented
Release 0.21.2 fixing this issue is now available on pypi.