Skip to content

No way to temporarily pass through requests(?) #270

Description

@flaeppe

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions