Pragmatic pytest: Getting started for Python devs Course

Course Summary

This course teaches you to effectively use Python's most popular and powerful test framework, pytest. pytest is partly so widely used because it's so fast to get started. However, many people stop with the basics and never learn pytest's true power.

In Getting started with pytest, you'll do so much more than just get started. You'll learn the five super powers of pytest: simple test functions, fixtures, parametrization, markers, and plugins. With this knowledge, you'll be able to test more effectively and efficiently, whenever you need to write software tests.

What students are saying

One of the best things I have enjoyed about going through these courses but especially this one is Michael breaks down the good and bad so you can see how different something accomplished. It simultaneously creates a connection of how maybe you executed code in other languages and the way it’s done in Python since a lot of time the syntax is very different. (Full review at https://bit.ly/2Y9YZL)
-- Roger T.

Source code and course GitHub repository

github.com/talkpython/getting-started-with-pytest-course

What will you learn?

In this course, you will:

  • Build clean, readable, well structured test functions.
  • Utilize fixtures to hold setup, teardown, and test data.
  • Share fixtures between tests and between test files.
  • Trace test execution through tests and fixtures to help debug tests.
  • Use test parametrization to create reams of test cases with a small number of test functions.
  • Identify test parametrizations cleanly with test ids.
  • Learn to skip tests with markers.
  • Run subsets of tests using keywords, markers, test classes, and combinations of these techniques.
  • Expand pytest functionality with pytest plugins.
  • And lots more
  • View the full course outline.

Who is this course for?

This course is for anyone who needs to test Python code, or anything reachable via Python code. Yep, pytest is being used to test APIs, web services, embedded systems, hardware, and of course Python packages, applications, and utilities.

Since many people are writing test code alongside their other work, the techniques presented in this course are focused on those that help you be efficient and effective with pytest.

Of course you can use these techniques if you are spending most of your time writing tests.

This course will be useful for software engineers of all flavors, including test engineers.

As for prerequisites, we assume:

  • *No software testing experience required
  • Familiarity with Python would be helpful.

Who am I? Why should you take my course?

My name is Brian Okken. There are a couple of reasons I'm especially qualified to teach you pytest.

  1. I wrote the first book on pytest, now in it's second edition, Python Testing with pytest.
  2. I host the #1 podcast on Python Testing, Test & Code.
  3. I'm experienced with pytest and Python testing. I've been using pytest to test Python applications and embedded C++ systems for over 10 years.
  4. I'm an experienced software engineer and lead engineer with 20+ years of industry experience. This is where I've learned to lean on efficient testing practices to help me write better applications faster.

Concepts backed by working code

Each chapter explores topics with working code. The code is all available to download or clone through GitHub. Each chapter is separated into directories.

While learning a topic, it's really important to run the code yourself, and explore it. Change the code, see what happens. Add new tests, break existing tests, have fun.

Follow along with subtitles and transcripts

Each course comes with subtitles and full transcripts. The transcripts are available as a separate searchable page for each lecture. They also are available in course-wide search results to help you find just the right lecture.

Each course has subtitles available in the video player.

This course is delivered in very high resolution

Example of 1440p high res video

This course is delivered in 1440p (4x the pixels as 720p). When you're watching the videos for this course, it will feel like you're sitting next to the instructor looking at their screen.

Every little detail, menu item, and icon is clear and crisp. Watch the introductory video at the top of this page to see an example.

Is this course based on Python 3 or Python 2?

This course is based upon Python 3. Python 2 is officially unsupported as of January 1st, 2020 and we believe that it would be ill-advised to teach or learn Python 2. This course is, and has always been, built around Python 3.

The time to act is now

pytest has become the defacto way we test Python software. If you are not up to speed with pytest and clean test practices, you'll be at a disadvantage. This course is focused on using the best techniques to provide a deep and meaningful understanding of software testing with pytest. Take the course, level up your productivity today.

Course Outline: Chapters and Lectures

Welcome to the course
10:28
Welcome
0:12
What is pytest?
0:18
Why pytest?
1:10
pytest vs. unittest
0:58
Topics covered
4:30
The cards app
1:27
Prerequisites
0:49
Meet your instructor
0:24
The companion book
0:40
Test Functions
44:01
Introducing test functions
1:26
Setting up our test environment
3:44
Writing our first tests
7:20
Running the cards application
3:43
A dataclass called Card
3:13
Unit testing the Card class
8:50
Enhanced assert tracebacks
3:27
Using pytest.fail() and Exceptions
2:29
Structuring test functions
3:38
Using test classes
2:40
Running a subset of tests
3:31
pytest Fixtures
52:29
Introducing test fixtures
1:21
Using fixtures to pass test data
2:31
Using fixtures for setup and teardown
6:26
Tracing execution with --setup-show
1:30
Testing cards with database setup and teardown
6:15
Moving setup and teardown into a fixture
4:05
Specifying fixture scope
5:05
Naive fix for test order dependency
1:16
Using multiple fixture levels
4:58
Sharing fixtures through conftest.py
4:58
Finding where fixtures are defined
3:08
Using builtin fixtures
4:43
Using multiple fixtures per test
4:34
Review
1:39
Parametrization
42:03
Introducing test parametrization
0:27
Manually testing "cards finish"
1:41
Testing without parametrization
8:09
Combining tests without parametrization
3:04
Parametrizing functions with two parameters
5:52
Parametrizing functions with one parameter
3:08
Stacking function parameters
3:30
Fixture parametrization
4:07
Using multiple parametrized fixtures
1:52
Using keywords to select test cases
3:58
Using ids for parameter objects
5:21
Review
0:54
Markers
23:35
Introducing markers
1:03
Skipping tests with pytest.mark.skip
4:02
Skipping tests conditionally with pytest.mark.skipif
3:11
Expecting tests to fail with pytest.mark.xfail
3:32
Selecting tests with custom markers
8:08
Using -ra to see reasons for all test outcomes
2:49
Review
0:50
pytest Plugins
11:38
Introducing pytest plugins
1:12
Finding plugins
2:29
Repeating tests with pytest-repeat
2:17
Running tests in parallel with pytest-xdist
1:27
Randomizing test order with pytest-random
3:01
Review
1:12
Configuration
23:00
Configuration and other non-test files
2:48
The non-test files in the cards application
5:14
Common settings in pytest.ini
6:29
Using pyproject.toml, tox.ini, or setup.cfg
1:39
Finding information about all possible settings
2:05
Avoiding test file name collision with __init__.py
3:52
Review
0:53
Course wrapup
2:29
What we learned and where to get more information
2:29
Buy for $59 + tax Bundle and save 85% Team Gift

Questions? Send us an email: contact@talkpython.fm

Talk Python's Mastodon Michael Kennedy's Mastodon