Colin-b / pytest_httpx

pytest fixture to mock HTTPX
https://colin-b.github.io/pytest_httpx/
MIT License
358 stars 30 forks source link

Setup httpx_mock via marker instead of fixtures #145

Closed RazerM closed 1 month ago

RazerM commented 6 months ago

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(
sonarcloud[bot] commented 6 months ago

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

melanisti commented 4 months ago

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

Colin-b commented 4 months ago

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

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Colin-b commented 1 month ago

This was released as part of version 0.31.0 today

RazerM commented 1 month ago

Thanks!