Test Overview
This test checks how pytest discovers test functions in a file based on naming conventions. It verifies that only functions starting with test_ are executed as tests.
This test checks how pytest discovers test functions in a file based on naming conventions. It verifies that only functions starting with test_ are executed as tests.
import pytest def test_addition(): assert 1 + 1 == 2 def addition_test(): assert 2 + 2 == 4 def test_subtraction(): assert 5 - 3 == 2 class TestMathOperations: def test_multiplication(self): assert 3 * 3 == 9 def multiplication_test(self): assert 4 * 4 == 16 if __name__ == "__main__": pytest.main(["-v"])
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and scans the test file for test functions and classes | pytest identifies functions and classes matching discovery rules | Functions starting with 'test_' and classes starting with 'Test' are selected | PASS |
| 2 | pytest runs function 'test_addition' | Function 'test_addition' executes | assert 1 + 1 == 2 | PASS |
| 3 | pytest skips function 'addition_test' because it does not start with 'test_' | Function 'addition_test' is not executed | - | PASS |
| 4 | pytest runs function 'test_subtraction' | Function 'test_subtraction' executes | assert 5 - 3 == 2 | PASS |
| 5 | pytest finds class 'TestMathOperations' and runs its method 'test_multiplication' | Method 'test_multiplication' executes | assert 3 * 3 == 9 | PASS |
| 6 | pytest skips method 'multiplication_test' because it does not start with 'test_' | Method 'multiplication_test' is not executed | - | PASS |
| 7 | Test run completes with all discovered tests passed | pytest reports 3 tests run, 0 failed, 0 skipped | - | PASS |