Test Overview
This test suite checks that tests run safely in parallel by using an autouse fixture to reset shared state before each test. It verifies that tests are independent, do not depend on execution order, and avoid interference.
This test suite checks that tests run safely in parallel by using an autouse fixture to reset shared state before each test. It verifies that tests are independent, do not depend on execution order, and avoid interference.
import pytest shared_resource = [] @pytest.fixture(scope="function", autouse=True) def reset_resource(): shared_resource.clear() assert len(shared_resource) == 0 yield @pytest.mark.parametrize('item', [1, 2, 3]) def test_append_item(item): # Each test starts with empty shared_resource due to fixture shared_resource.append(item) assert len(shared_resource) == 1 assert item in shared_resource def test_shared_resource_length(): # This test verifies the resource is reset (empty) assert len(shared_resource) == 0
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Fixture reset_resource runs before test_append_item[1], clears shared_resource | shared_resource is empty [] | Assert length == 0 (fixture) | PASS |
| 2 | test_append_item[1] appends 1 | shared_resource contains [1] | Assert len == 1 and 1 in shared_resource | PASS |
| 3 | Fixture reset_resource runs before test_append_item[2], clears shared_resource | shared_resource is empty [] | Assert length == 0 (fixture) | PASS |
| 4 | test_append_item[2] appends 2 | shared_resource contains [2] | Assert len == 1 and 2 in shared_resource | PASS |
| 5 | Fixture reset_resource runs before test_append_item[3], clears shared_resource | shared_resource is empty [] | Assert length == 0 (fixture) | PASS |
| 6 | test_append_item[3] appends 3 | shared_resource contains [3] | Assert len == 1 and 3 in shared_resource | PASS |
| 7 | Fixture reset_resource runs before test_shared_resource_length, clears shared_resource | shared_resource is empty [] | Assert length == 0 (fixture) | PASS |
| 8 | test_shared_resource_length checks length | shared_resource is empty [] | Assert length == 0 | PASS |