-
Notifications
You must be signed in to change notification settings - Fork 38
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
No way to temporarily pass through requests(?) #270
Comments
To clarify I meant a minimal case looking along the lines of: import httpx
import pytest
import respx
@pytest.fixture(scope="session", autouse=True)
def _disable_external_httpx_calls():
with respx.mock:
yield None
def test_first():
respx.route(host="localhost").pass_through()
httpx.get("http://localhost:8000/")
def test_second():
httpx.get("http://localhost:8000/") If |
I managed to figure out that since it's a global object involved I can create a fixture that wraps the pass through in a snapshot that'll get rolled back. It auto-enables respx mocking essentially doing duplicate work, and it's slightly more verbose but that's only visible in the allowing fixture. But it's something that works at least. @pytest.fixture(scope="session", autouse=True)
def _disable_external_httpx_calls():
with respx.mock:
yield None
@pytest.fixture()
def allow_localhost():
with respx.mock:
respx.route(host="localhost").pass_through()
yield |
In my suite a want the global default behaviour of disabling all external calls, unless explicitly excepted by a pass through.
I have the following fixture in a "root conftest.py" disabling calls:
But now I want to, for a limited part of my tests, pass through some external request e.g.
But as far as I can tell, the above pass through is globally configured. Which means that after I've called
.pass_through()
there's no reverting it.Optimally I'd like to scope the pass through for a limited context, e.g.
The text was updated successfully, but these errors were encountered: