Test Overview
This test suite shows two independent tests using pytest. Each test checks a simple math operation without relying on the other test's result. This avoids test interdependence, ensuring tests can run in any order and still pass.
Jump into concepts and practice - no test required
This test suite shows two independent tests using pytest. Each test checks a simple math operation without relying on the other test's result. This avoids test interdependence, ensuring tests can run in any order and still pass.
import pytest # Test 1: Check addition def test_addition(): result = 2 + 3 assert result == 5 # Test 2: Check multiplication def test_multiplication(): result = 4 * 5 assert result == 20
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and discovers test_addition | No tests have run yet | — | PASS |
| 2 | test_addition executes: calculates 2 + 3 | Calculation done, result = 5 | Assert result == 5 | PASS |
| 3 | Test runner discovers test_multiplication | test_addition passed, no shared state | — | PASS |
| 4 | test_multiplication executes: calculates 4 * 5 | Calculation done, result = 20 | Assert result == 20 | PASS |
shared_list = []
def test_add_one():
shared_list.append(1)
assert shared_list == [1]
def test_add_two():
shared_list.append(2)
assert shared_list == [2]data = {}
def test_set_value():
data['key'] = 'value'
assert data['key'] == 'value'
def test_check_empty():
assert data == {}