flowchart LR
A[Input] --> B[Function] --> C[Output] -.-> D[Assert: Output correct]
Writing reliable code through automated testing
Software testing is the act of checking whether software satisfies expectations.
Update code without fear
Avoid performance degradation over time
Useful for catching algorithmic regressions
Measure time for one execution (if short, many)
Challenge: Find a test that runs fast but catches real problems
Set realistic thresholds that won’t fail due to system load
flowchart LR
A[Input] --> B[Function] --> C[Output] -.-> D[Assert: Output correct]
flowchart LR
A[Module A] -->|data| B[Module B]
B -.-> D[Assert: data transfer correct]
Do not test with real data/systems
Your production is not a system test!
flowchart TD A["Arrange for test"] --> B["Act"] --> C["Assert result"]
The entire process should run fully automatically.
Testing that a writer and reader work together correctly:
import pytest
from io_module import save_results, load_results
def test_save_load_roundtrip(tmp_path):
data = [1.0, 2.5, 3.14] # Arrange: data
path = tmp_path / "results.txt" # Arrange: temp file
save_results(path, data) # Act: write
result = load_results(path) # Act: read back
assert result == data # Assert: data survived the round-trippytestSimple and powerful testing framework for Python
pytest looks for teststest_*.py or *_test.pytest_*pytest FixturesFixtures provide reusable setup (and teardown) for tests
tmp_path is a built-in pytest fixture, cleaned up after the testpytestpytest