-
Notifications
You must be signed in to change notification settings - Fork 31
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
Document how to configure options on the whole test suite #154
Comments
Hello @Apakottur , I am not proficient enough with pytest marks to give you a definitive answer on this. If not, I am sure we could cook something up. If you are using this option because you have a shared fixture registering a lot of responses that might not be useful in all tests, you could have a look at calling the following method at teardown (after the yield statement of your fixture). httpx_mock.reset() This would however prevent any assertion performed at teardown by httpx_mock (your test suite would not fail at teardown if some HTTP calls were not mocked, but your tests might still fail depending on how your code handle the Timeout raised by httpx_mock when nothing was registered). |
You could add this to your root def pytest_collection_modifyitems(session, config, items):
for item in items:
item.add_marker(pytest.mark.httpx_mock(assert_all_responses_were_requested=False)) |
Also maybe we should change pytest_httpx/pytest_httpx/__init__.py Line 23 in ca067b4
to use pytestmark = pytest.mark.httpx_mock(assert_all_responses_were_requested=False)
@pytest.mark.httpx_mock(non_mocked_hosts=["example.com"])
def test_foo():
... |
Nice, so there is a workaround. Indeed we should fix the way we currently handle provided options. And this ticket is now a documentation update one |
This works perfectly for our usecase, thank you! |
Documentation was updated to help setting this up and code now handles multiple level of configuration |
We are using the
assert_all_responses_were_requested
option in our test suite to avoid raising an error if not all responses were requested.We have thousands of unit tests across hundreds of test files that would error without this flag being set to
False
so we were using the fixture to set it to false globally for the entire test suite.The changes in #145 now make this flag scoped, which is a great feature, but not applicable in our case, meaning we can't use the newest version of the package.
It would be great to still be able to configure it once for the entire test suite (otherwise we'd have to add it to hundreds of files).
Or perhaps it's possible to configure it globally for entire test suite and I'm just missing something?
The text was updated successfully, but these errors were encountered: