Skip to content

Lesson 20 · Python

Professional Practice: Testing with pytest

Write your first automated tests with pytest: arrange-act-assert, parametrize for edge cases, fixtures, pytest.raises - and red-green TDD as a taste, not a religion.

45 minintermediateProfessional Practice

Prerequisites: Databases: Python & SQLite in Practice

Learning objectives
By the end of this lesson, you will be able to:
  • Explain what automated tests buy you: regression safety and design feedback
  • Write test functions in the arrange-act-assert shape with plain assert
  • Install and run pytest, and read its output to find what broke and why
  • Cover edge cases with @pytest.mark.parametrize instead of copy-pasted tests
  • Assert raised exceptions with pytest.raises and share setup with a fixture