Test Overview
This test checks that a simple function returns the correct result and uses proper test naming conventions in pytest. It verifies that the test function name starts with test_ so pytest can discover and run it.
Jump into concepts and practice - no test required
This test checks that a simple function returns the correct result and uses proper test naming conventions in pytest. It verifies that the test function name starts with test_ so pytest can discover and run it.
import pytest def add(a, b): return a + b def test_add_two_numbers(): result = add(2, 3) assert result == 5
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and discovers test functions starting with 'test_' | pytest collects test_add_two_numbers from the test file | — | PASS |
| 2 | pytest runs test_add_two_numbers function | Inside test_add_two_numbers, calls add(2, 3) | — | PASS |
| 3 | Assert that result equals 5 | result is 5 from add function | assert result == 5 | PASS |
| 4 | Test completes successfully | pytest reports test_add_two_numbers PASSED | — | PASS |
test_.test_, so pytest will find it automatically.def test_addition():
assert 1 + 1 == 2
def check_subtraction():
assert 2 - 1 == 1
def testMultiplication():
assert 2 * 3 == 6
class TestDivision:
def test_divide(self):
assert 6 / 2 == 3
test_ and methods inside classes named Test* starting with test_.test_addition is found; check_subtraction is ignored; testMultiplication is ignored due to camelCase; test_divide inside TestDivision class is found.Test_login but pytest does not run it. What is the most likely reason?test_ exactly.Test_loginT, so pytest ignores it.