Unit-Testing

How to Write Unit Tests in Python with pytest

This guide builds a small bakery order module, then covers it with pytest: plain assert-based tests, pytest.raises for exceptions, fixtures for shared setup, parametrize for testing many cases at once, and unittest.mock for isolating a flaky external call.

July 15, 2026 in Python, Tools by Mehdi Lotfinejad10 minutes