Test Overview
This test suite demonstrates test independence by ensuring each test runs separately without relying on shared state. It verifies that modifying data in one test does not affect others.
This test suite demonstrates test independence by ensuring each test runs separately without relying on shared state. It verifies that modifying data in one test does not affect others.
import pytest @pytest.fixture def sample_list(): return [1, 2, 3] def test_append_item(sample_list): sample_list.append(4) assert sample_list == [1, 2, 3, 4] def test_original_list_unchanged(sample_list): assert sample_list == [1, 2, 3]
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and collects tests | No tests executed yet | - | PASS |
| 2 | Runs test_append_item with fresh sample_list fixture | sample_list = [1, 2, 3] | Check sample_list after append is [1, 2, 3, 4] | PASS |
| 3 | Runs test_original_list_unchanged with fresh sample_list fixture | sample_list = [1, 2, 3] | Check sample_list is still [1, 2, 3] | PASS |