Support excluding mocked endpoints by URL path
Background
- I am currently using pytest_httpx to mock only part of an external API, such as “https://sample_api/mocked”, while avoiding mocking “https://sample_api/not_mocked”.
Problem Statement
- From my understanding, there is no way to achieve this using the non_mocked_hosts option.
- Are there any ways to achieve this?
Proposed Solution
- Add options to exclude a certain URL path from mocked targets
I am willing to create a PR to implement this feature if you could point me in the right direction. Thank you for your time and for maintaining this project. I apologize if my English is not perfect, as it is not my first language. This is also my first time posting an issue on GitHub, so please let me know if there are any questions or feedback.
Hello @wtberry
This is indeed a valid use case, thanks for pointing that out. If you feel like drafting a pull request go ahead!
I propose to do a breaking change release and rename the non mocked hosts into something like non mocked urls. Were you could provide regular expressions to keep the previous behavior while also supporting your use case.
I am also wondering if we shouldn't change this to something a bit more generic like exposing the ability to provide a function to mock or not a request (it would then return a boolean and would allow to filter on more than URL)
should_mock option will be available in next release (0.33.0)
@Colin-b I'm sorry I didn't get to implement this, thank you so much for doing this. Would you be able to inform me when the next release would be?
Version 0.33.0 is now available on pypi with this feature.