Verify that the sum of two numbers is correct
Preconditions (2)
✅ Expected Result: The assert statement passes confirming the sum is correct
def add_numbers(a: int, b: int) -> int: return a + b def test_add_numbers(): result = add_numbers(2, 3) assert result == 5, f"Expected 5 but got {result}"
The add_numbers function adds two numbers and returns the result.
The test function test_add_numbers calls this function with 2 and 3, then uses an assert statement to check if the result is 5.
If the result is not 5, the assert will fail and show a clear message.
This simple test shows how to use basic assert statements in pytest.
Now add data-driven testing with 3 different pairs of numbers and their expected sums
assert statement do in a pytest test?def test_value():
x = 10
assert x < 5, "x is not less than 5"def test_sum():
total = 3 + 4
assert total = 7, "Sum should be 7"items contains exactly 3 elements using pytest assert. Which is the best assert statement?Pass the test and this pattern moves unknown