Skip to content

Conversation

@JacobHayes
Copy link

I wanted to override assert_all_called=True for my entire test suite, but couldn't quite see how from the docs. This PR adds info on how to override the respx_mock fixture at both the module level and globally.

@lundberg
Copy link
Owner

How to globally enable respx is a great suggestion to the docs.

Normally I use an auto-used session scoped fixture for this, e.g. @pytest.fixture(scope="session", autouse=True). An autouse fixture may be simpler a more common test pattern (?).

Maybe the docs on custom fixtures would be a better place to include an example at .. possibly with a link from the guide.

@JacobHayes
Copy link
Author

Hmm yeah an autouse fixture is probably better for most uses.

In my case, I didn't want to affect httpx in tests that weren't otherwise mocking, so an autouse fixture (which would add mocking) wasn't ideal.

@lundberg
Copy link
Owner

Well, mocking httpx for the test suite globally is preferred, preventing any external unwanted/accidental calls to be made .. at least IMO 😉 i.e. it's a good workflow when the test suite is able to run anywhere, without remote access.

@lundberg
Copy link
Owner

BTW, the idea behind #227 is to allow the user to configure respx's default response/sideeffect e.g. NetworkError, to optionally simulating lack of network/remote access, and enforce the user to mock suitable responses for the endpoints called.

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.

2 participants