Test Overview
This test demonstrates how pytest markers categorize tests and control which tests run. It verifies that only tests with a specific marker run when selected.
This test demonstrates how pytest markers categorize tests and control which tests run. It verifies that only tests with a specific marker run when selected.
import pytest @pytest.mark.slow def test_slow_feature(): assert 2 + 2 == 4 @pytest.mark.fast def test_fast_feature(): assert 1 + 1 == 2 # Run command: pytest -m slow
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and reads test file | Test file with two tests: one marked 'slow', one marked 'fast' | - | PASS |
| 2 | Pytest filters tests to run only those marked 'slow' using '-m slow' | Only test_slow_feature is selected to run | - | PASS |
| 3 | Pytest runs test_slow_feature | Executing test_slow_feature function | Assert 2 + 2 == 4 | PASS |
| 4 | Pytest deselects test_fast_feature because it is not marked 'slow' | test_fast_feature is deselected | - | PASS |
| 5 | Test run completes with only 'slow' tests executed | Test report shows 1 passed, 1 deselected, 0 skipped | Verify only tests with 'slow' marker ran | PASS |