pytest_httpx icon indicating copy to clipboard operation
pytest_httpx copied to clipboard

Setup httpx_mock via marker instead of fixtures

Open RazerM opened this issue 1 year ago • 3 comments

Resolves #137

We want to be able to configure how the httpx_mock fixture behaves at different scopes. A pytest marker can be used at module, class, or test scope and so is what is used here.

Providing a non-default value from the fixtures will emit a DeprecationWarning for each test with the exact marker it can be replaced with:

=================================== warnings summary ===================================
tests/test_tmp.py::test_a
tests/test_tmp.py::test_b
  /.../pytest_httpx/__init__.py:56: DeprecationWarning: The assert_all_responses_were_requested and non_mocked_hosts fixtures are deprecated.
  Use the following marker instead:

  pytest.mark.httpx_mock(assert_all_responses_were_requested=False)

    warnings.warn(

tests/test_tmp.py::test_c
  /.../pytest_httpx/__init__.py:56: DeprecationWarning: The assert_all_responses_were_requested and non_mocked_hosts fixtures are deprecated.
  Use the following marker instead:

  pytest.mark.httpx_mock(non_mocked_hosts=['example.com'])

    warnings.warn(

RazerM avatar Apr 26 '24 14:04 RazerM

Guys, thank you so much for this pullrequest. It's a great library, but it's a feature it really lacks

melanisti avatar Jun 19 '24 10:06 melanisti

I agree, I plan on looking to this as soon as I have some free time. hang in there

Colin-b avatar Jun 19 '24 13:06 Colin-b

This was released as part of version 0.31.0 today

Colin-b avatar Sep 20 '24 10:09 Colin-b

Thanks!

RazerM avatar Sep 21 '24 15:09 RazerM