Python Testing
Python offers unittest (built-in) and pytest (third-party, preferred). Tests verify correctness, catch regressions, and document expected behaviour.
Python offers unittest (built-in) and pytest (third-party, preferred). Tests verify correctness, catch regressions, and document expected behaviour.
# Install pytest
pip install pytest
# Write tests in test_*.py files
def test_addition():
assert 1 + 1 == 2
# Run
pytest # all tests
pytest -v # verbose
pytest test_math.py # single file
pytest -k "addition" # by keyword
pytest auto-discovers test_*.py files and functions starting with test_ — no boilerplate needed.