Mathew K Analytics

Learn pytest with free notebooks

20 free video lessons that use pytest, each with a downloadable Jupyter notebook and, where needed, the dataset. Learn pytest by working through real examples.

About these pytest lessons

pytest is the most widely used testing framework for Python. These lessons go from your first test to testing a real package: fixtures and their scopes, conftest.py, parametrize, mocking and monkeypatch, markers, assertions, temporary files, capturing output and logs, testing exceptions and warnings, coverage with pytest-cov, parallel runs with pytest-xdist, plugins, and running your tests in CI.

These 20 lessons come from 3 different courses, so you see pytest used in several settings. The course with the most pytest lessons is Pytest deep dive (18 lessons).

pytest is most often used here together with logging, JSON, pathlib and subprocess.

Watch the video, then run the notebook yourself: changing the code and re-running it is the fastest way to learn.

Courses that use pytest

Python Debugging for Beginners: Read Errors, Fix Bugs, Write Tests (Beginner Python Course, Part 5)59 min
Lesson 5

Python Debugging for Beginners: Read Errors, Fix Bugs, Write Tests (Beginner Python Course, Part 5)

📓 Notebook · pytest · pathlib · logging

FastAPI Tutorial #17: Testing FastAPI Apps with pytest
Lesson 17

FastAPI Tutorial #17: Testing FastAPI Apps with pytest

📓 Notebook · FastAPI · pytest · Pydantic

pytest Tutorial #1: Getting Started — Your First Python Test
Lesson 1

pytest Tutorial #1: Getting Started — Your First Python Test

📓 Notebook · pytest

pytest Tutorial #2: Fixtures Basics
Lesson 2

pytest Tutorial #2: Fixtures Basics

📓 Notebook · pytest

pytest Tutorial #3: Parametrize — Many Cases, One Test
Lesson 3

pytest Tutorial #3: Parametrize — Many Cases, One Test

📓 Notebook · pytest

pytest Tutorial #4: Mocking & Monkeypatch
Lesson 4

pytest Tutorial #4: Mocking & Monkeypatch

📓 Notebook · unittest · pytest · datetime

pytest Tutorial #5: Markers — Organising and Selecting Tests
Lesson 5

pytest Tutorial #5: Markers — Organising and Selecting Tests

📓 Notebook · pytest

pytest Tutorial #6: Assertions Deep Dive
Lesson 6

pytest Tutorial #6: Assertions Deep Dive

📓 Notebook · pytest

pytest Tutorial #7: conftest.py & Sharing Fixtures
Lesson 7

pytest Tutorial #7: conftest.py & Sharing Fixtures

📓 Notebook · pytest

pytest Tutorial #8: Fixture Scopes & Finalisation
Lesson 8

pytest Tutorial #8: Fixture Scopes & Finalisation

📓 Notebook · pytest

pytest Tutorial #9: Test Organisation That Scales
Lesson 9

pytest Tutorial #9: Test Organisation That Scales

📓 Notebook · pytest

pytest Tutorial #10: Parametrised & Indirect Fixtures
Lesson 10

pytest Tutorial #10: Parametrised & Indirect Fixtures

📓 Notebook · pytest

pytest Tutorial #11: Plugins — Extending pytest
Lesson 11

pytest Tutorial #11: Plugins — Extending pytest

📓 Notebook · pytest

pytest Tutorial #12: Coverage with pytest-cov
Lesson 12

pytest Tutorial #12: Coverage with pytest-cov

📓 Notebook · pytest

pytest Tutorial #13: Temporary Files & Directories
Lesson 13

pytest Tutorial #13: Temporary Files & Directories

📓 Notebook · pytest · JSON

pytest Tutorial #14: Capturing Output & Logs
Lesson 14

pytest Tutorial #14: Capturing Output & Logs

📓 Notebook · logging · pytest

pytest Tutorial #15: Parallel Testing with pytest-xdist
Lesson 15

pytest Tutorial #15: Parallel Testing with pytest-xdist

📓 Notebook · pytest

pytest Tutorial #16: Testing Exceptions & Warnings
Lesson 16

pytest Tutorial #16: Testing Exceptions & Warnings

📓 Notebook · pytest

pytest Tutorial #17: CI Integration & Configuration
Lesson 17

pytest Tutorial #17: CI Integration & Configuration

📓 Notebook · pytest

pytest Tutorial #18: Capstone — Testing a Real Package End to End
Lesson 18

pytest Tutorial #18: Capstone — Testing a Real Package End to End

📓 Notebook · pytest · JSON · logging

Frequently asked questions

Where should I start learning pytest?

Start with “Python Debugging for Beginners: Read Errors, Fix Bugs, Write Tests (Beginner Python Course, Part 5)”, then work through the Pytest deep dive course.

Are these pytest lessons free?

Yes. Every video, notebook and dataset on this site is free to use for learning.

Can I run the pytest notebooks without installing Python?

Yes. Open them in Google Colab, or use the Run in browser button where a lesson has one.