Test Overview
This test checks if the addition of two numbers works correctly using PyTest. It verifies that 2 + 3 equals 5.
This test checks if the addition of two numbers works correctly using PyTest. It verifies that 2 + 3 equals 5.
import pytest def test_addition(): result = 2 + 3 assert result == 5
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | PyTest test runner is ready to execute tests | — | PASS |
| 2 | Calls test_addition function | Inside test function, variables initialized | — | PASS |
| 3 | Calculates result = 2 + 3 | result variable holds value 5 | — | PASS |
| 4 | Checks assertion assert result == 5 | Comparing result (5) with expected value (5) | Assert that result equals 5 | PASS |
| 5 | Test ends successfully | Test runner marks test as passed | — | PASS |
test_.test_ are recognized as tests by default.test_, so test_add is correct.1 + 1 == 2 is true, so the test will pass.def test_example():
x = 5
y = 2
assert x - y == 3x - y which is 5 - 2 = 3.3 == 3, which is true, so no error is raised.def test_sum():
total = 2 + 2
assert total = 4= which is assignment, not comparison. It should be ==.test_ and indentation is correct, so no error there.multiply(a, b) that returns the product of two numbers. Which PyTest test function correctly tests that multiply(3, 4) returns 12?test_, so test_multiply is correct.== and the expected result is 12, so assert multiply(3, 4) == 12 is correct.Pass the test and this pattern moves unknown