Test Overview
This test uses a pytest fixture to provide a sample list to the test function. It verifies that the fixture correctly supplies the data and that the test can access and assert the list contents.
This test uses a pytest fixture to provide a sample list to the test function. It verifies that the fixture correctly supplies the data and that the test can access and assert the list contents.
import pytest @pytest.fixture def sample_list(): return [1, 2, 3, 4, 5] def test_sum_of_list(sample_list): total = sum(sample_list) assert total == 15 assert len(sample_list) == 5
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | pytest test runner initialized | - | PASS |
| 2 | pytest discovers the fixture 'sample_list' | Fixture 'sample_list' is registered and ready to be used | - | PASS |
| 3 | pytest calls test function 'test_sum_of_list' with 'sample_list' fixture as argument | The fixture function 'sample_list' is executed, returning [1, 2, 3, 4, 5] | - | PASS |
| 4 | Inside test, sum(sample_list) is calculated | sum is 15 | assert total == 15 | PASS |
| 5 | Inside test, length of sample_list is checked | length is 5 | assert len(sample_list) == 5 | PASS |
| 6 | Test completes successfully | Test passed with no errors | - | PASS |