Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup httpx_mock via marker instead of fixtures #145

Merged
merged 3 commits into from
Sep 19, 2024

Conversation

RazerM
Copy link
Contributor

@RazerM RazerM commented Apr 26, 2024

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(

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_r
esponses_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_r
esponses_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(

Resolves Colin-b#137
@RazerM RazerM force-pushed the feature/httpx-mock-marker branch from ac2edad to 5b4540f Compare April 26, 2024 14:19
Copy link

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
Copy link

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

@Colin-b
Copy link
Owner

Colin-b commented Jun 19, 2024

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

Copy link

@Colin-b Colin-b self-requested a review September 19, 2024 20:47
Copy link
Owner

@Colin-b Colin-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thx again for the nice work. I will however drop the support for previous features, this is going to be a breaking change release anyway and changelog + readme document it well enough.

Really nice PR once again, it's refreshing to see actual clean code :)

@Colin-b Colin-b merged commit 5b799cc into Colin-b:develop Sep 19, 2024
5 checks passed
@RazerM RazerM deleted the feature/httpx-mock-marker branch September 19, 2024 21:05
@Colin-b
Copy link
Owner

Colin-b commented Sep 20, 2024

This was released as part of version 0.31.0 today

@RazerM
Copy link
Contributor Author

RazerM commented Sep 21, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce decorators to setup httpx_mock
3 participants