Test Overview
This test demonstrates how a pytest fixture with module scope behaves when running tests in parallel. It verifies that the fixture is created once per module and shared across parallel test functions.
This test demonstrates how a pytest fixture with module scope behaves when running tests in parallel. It verifies that the fixture is created once per module and shared across parallel test functions.
import pytest @pytest.fixture(scope="module") def resource(): print("Setup resource") yield "resource_data" print("Teardown resource") @pytest.mark.parametrize("input", [1, 2]) def test_parallel(resource, input): assert resource == "resource_data" assert input in [1, 2]
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and collects tests | Two test cases found: test_parallel with input=1 and input=2 | - | PASS |
| 2 | Pytest initializes fixture 'resource' with scope='module' | Fixture setup prints 'Setup resource' | Fixture resource is created once for the module | PASS |
| 3 | Tests run in parallel threads/processes for input=1 and input=2 | Both tests receive the same fixture instance 'resource_data' | Each test asserts resource == 'resource_data' and input in [1, 2] | PASS |
| 4 | After all tests complete, fixture teardown runs | Fixture teardown prints 'Teardown resource' | Fixture teardown happens once after all tests | PASS |