0

Using requests_mock I can check if it was called with call_count attribute like in the example below:

def test_foo(
    self,
    response,
    mock_service,
):
    assert mock_service.call_count == 1

But now I'm using httpx library. How I can check the same in it?

Tony
  • 3
  • 2

1 Answers1

0

You can use pytest-httpx to mock httpx. Then you will be able to check every request that was issued. Or simply check the number of issued requests via:

def test_nb_queries(httpx_mock):
    assert len(httpx_mock.get_requests()) == 2

And if there is a single request expected, you can even do:

def test_single_query(httpx_mock):
    assert httpx_mock.get_request()
Colin B
  • 94
  • 6