Verify addition function returns correct sum
Preconditions (2)
✅ Expected Result: The test passes confirming the add function returns the correct sum
def add(a, b): return a + b def test_add(): result = add(2, 3) assert result == 5, f"Expected 5 but got {result}"
The add function simply returns the sum of two numbers.
The test function test_add calls add(2, 3) and stores the result.
It then uses assert to check if the result is 5.
If the assertion fails, pytest will show the message with the actual result.
This test function is simple, clear, and follows pytest naming conventions.
Now add data-driven testing with 3 different input pairs and expected sums
def test_sum():
result = 2 + 3
assert result == 5def test_multiply():
result = 4 * 5
assert result = 20def max_number(numbers):
return max(numbers)
# Choose the correct test function:Pass the test and this pattern moves unknown