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

Flaky reruns autouse session-scoped fixtures when a tests fails one of its runs #207

Open
JimArnow opened this issue Apr 1, 2024 · 0 comments

Comments

@JimArnow
Copy link

JimArnow commented Apr 1, 2024

When a test fails and is rerun, Flaky reruns session-scoped autouse fixtures. For example, running this test:

import pytest

@pytest.fixture(scope="session", autouse=True)
def my_session_scoped_autouse_fixture():
    print("\nIn session scope autouse fixture")

@pytest.mark.flaky(max_runs=3)
def test_flaky_reruns(local_list = []):
    local_list.append(0)
    assert len(local_list)==3

calls the fixture 3 times:

============================= test session starts ==============================
collecting ... collected 1 item

test_it.py::test_flaky_reruns 
In session scope autouse fixture

In session scope autouse fixture

In session scope autouse fixture
PASSED

============================== 1 passed in 0.01s ===============================

Process finished with exit code 0

This can cause unexpected behaviors. In my case, I'm using the pytest-playwright package which has a session-scoped autouse fixture that deletes the output directory where traces are stored for failing tests. If a test fails and is rerun, any previously created trace files are deleted.

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