Skip to content
AgileLogics
5 min read

Testing

Prerequisites: Functions

pytest is the standard testing tool in Python (pip install pytest). A test is a function whose name starts with test_, containing assert statements that check expected behavior.

# calculator.py
def add(a, b):
    return a + b
# test_calculator.py
from calculator import add

def test_add():
    assert add(2, 3) == 5
    assert add(-1, 1) == 0
pytest

Running pytest automatically finds every test_* function in the project and reports which passed or failed — catching the moment a change breaks something that used to work.