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:
@pytest.fixture(scope="session", autouse=True)
def _disable_external_httpx_calls() -> Generator[None, None, None]:
with respx.mock:
yield None
But now I want to, for a limited part of my tests, pass through some external request e.g.
def test_something():
respx.route(host="localhost").pass_through()
...
# Test done, but "localhost" will still be allowed
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.
def test_something():
with respx.route(host="localhost").pass_through():
...
# Test done, "localhost" disabled
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.