Test Overview
This test uses the @pytest.fixture decorator to create a reusable setup function that provides a sample list. The test verifies that the list contains the expected number of elements.
This test uses the @pytest.fixture decorator to create a reusable setup function that provides a sample list. The test verifies that the list contains the expected number of elements.
import pytest @pytest.fixture def sample_list(): return [1, 2, 3, 4, 5] def test_list_length(sample_list): assert len(sample_list) == 5
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | PyTest collects test functions and fixtures | Test runner is ready with test_list_length and fixture sample_list | - | PASS |
| 2 | PyTest calls fixture sample_list before test_list_length | sample_list fixture returns [1, 2, 3, 4, 5] | - | PASS |
| 3 | test_list_length receives sample_list as argument and runs assertion | Inside test, sample_list is [1, 2, 3, 4, 5] | Check if length of sample_list is 5 | PASS |
| 4 | Test completes successfully | Test runner shows test_list_length PASSED | - | PASS |