Test Overview
This test checks that a shared resource (a simple counter) is correctly reset before each test to avoid interference between tests.
This test checks that a shared resource (a simple counter) is correctly reset before each test to avoid interference between tests.
import pytest shared_counter = {'count': 0} @pytest.fixture(autouse=True) def reset_counter(): shared_counter['count'] = 0 def test_increment_once(): shared_counter['count'] += 1 assert shared_counter['count'] == 1 def test_increment_twice(): shared_counter['count'] += 2 assert shared_counter['count'] == 2
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and loads the test module | shared_counter dictionary initialized with count = 0 | - | PASS |
| 2 | Before test_increment_once runs, reset_counter fixture sets shared_counter['count'] to 0 | shared_counter['count'] is 0 | - | PASS |
| 3 | test_increment_once increments shared_counter['count'] by 1 | shared_counter['count'] is 1 | assert shared_counter['count'] == 1 | PASS |
| 4 | Before test_increment_twice runs, reset_counter fixture sets shared_counter['count'] to 0 again | shared_counter['count'] reset to 0 | - | PASS |
| 5 | test_increment_twice increments shared_counter['count'] by 2 | shared_counter['count'] is 2 | assert shared_counter['count'] == 2 | PASS |