Udemy
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
pytest Complete Guide|Python Unit Testing with 50 Exercises
15 students

pytest Complete Guide|Python Unit Testing with 50 Exercises

Master real-world Python testing through 50 hands-on labs: assert, parametrize, fixture, mock, coverage, FastAPI, TDD
Created byM Sakai
Last updated 10/2026
English

What you'll learn

  • Understand how pytest discovers tests and write clear, meaningful unit tests on your own using assert, approx, and raises
  • Design maintainable, duplication-free tests with parametrize, fixture, and conftest, and manage quality using markers, skips, and coverage
  • Replace external dependencies with monkeypatch, the standard mock library, and pytest-mock to write fast, stable tests that never touch the network or a DB
  • Experience professional-level testing: FastAPI endpoint tests, async tests with httpx, snapshot testing, and CI-style one-shot runs
  • Practice TDD (test-driven development) hands-on and learn to build code starting from tests written against the specification

Course content

14 sections • 104 lectures • 9h 51m total length
  • Course Overview6:18
  • How the Course Is Conducted4:20
  • Google Cloud Shell documentation and usage limits0:49
  • Exercise materials and Google Cloud Shell setup3:24

Requirements

  • Basic Python syntax (variables, functions, imports, lists, dicts) is all you need. No prior experience with testing or pytest is required
  • A PC with an internet connection and a browser is enough. All exercises run on Google Cloud Shell, so no local environment setup is needed

Description

This course contains the use of artificial intelligence.

This is a hands-on pytest course that lifts your Python code from "it probably works" to "it works, and the tests prove it." It is designed so that people with zero testing experience can move forward one step at a time, starting from their very first `assert`.

The heart of this course is 50 hands-on exercises - you will not just watch. Every lesson follows the same rhythm: a walkthrough video, an exercise you solve yourself, and a review video covering the model answer. Repeating that loop 50 times, writing real code and turning tests green, is how knowledge turns into something your hands remember. Upload the exercise ZIP to Google Cloud Shell and run the included setup script. No local Python installation is required. You need a Google account; free quotas are 50 hours per week and 5GB of storage. Accounts under 18 or with unknown age cannot use Cloud Shell. A local Python alternative is included. When videos show CodeSandbox, follow the updated startup lecture instead. Grading requires no API keys or paid Cloud resources.

The content comes in two parts. Part 1 builds the core: how pytest collects tests automatically, the plain `assert` statement, comparing floats with approx, verifying exceptions with raises, data-driven testing with parametrize, sharing setup through fixtures and conftest, markers and skips, and measuring coverage. Part 2 covers what you meet at work: monkeypatch, the standard mock library and pytest-mock, verifying loggers and standard output, file I/O and SQLite, testing FastAPI APIs, async tests with httpx, snapshot testing, and capstone exercises that keep TDD and CI in mind.

Go from "how am I even supposed to write a test?" to "I can put meaningful tests on my own code with confidence." Let's make testing your ally and become an engineer who writes code that does not break.

Who this course is for:

  • Python learners and working engineers who can write code but have no idea how to write tests, or who keep putting testing off
  • Anyone who knows the words unit test, TDD, mock, coverage, and CI, but wants to learn them systematically by actually writing code
  • Web developers using FastAPI who want automated tests for their APIs and logic so they can refactor with confidence