Skip to content
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

The disable_network marker does not disable network in fixtures #13

Open
jond01 opened this issue Oct 28, 2023 · 0 comments
Open

The disable_network marker does not disable network in fixtures #13

jond01 opened this issue Oct 28, 2023 · 0 comments

Comments

@jond01
Copy link

jond01 commented Oct 28, 2023

Env.

  • Python 3.11
  • Pytest 7.4.3
  • pytest-network@4e98d81 (current master)

Case

The following test passes:

import urllib.request

import pytest


@pytest.fixture
def some_network_resource() -> str:
    with urllib.request.urlopen(
        "https://github.com/best-doctor/pytest_network"
    ) as response:
        return response.read().decode()


@pytest.mark.disable_network
def test_network_disabled(some_network_resource: str) -> None:
    assert some_network_resource

The expected behavior is a failure.

Explanation

The fixture runs before the pytest_runtest_call hook:

def pytest_runtest_call(item):

Proposed solution

Change L52 above to pytest_runtest_setup:

def pytest_runtest_setup(item):

See also:

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

No branches or pull requests

1 participant