Skip to Main Content
Python Testing with pytest
book

Python Testing with pytest

by Brian Okken
February 2022
Intermediate to advanced content levelIntermediate to advanced
274 pages
6h 28m
English
Pragmatic Bookshelf
Content preview from Python Testing with pytest

Running a Subset of Tests

In the previous section, we used test classes to be able to run a subset of tests. Running just a small batch of tests is handy while debugging or if you want to limit the tests to a specific section of the code base you are working on at the time.

pytest allows you to run a subset of tests in several ways:

Subset

Syntax

Single test method

pytest path/test_module.py::TestClass::test_method

All tests in a class

pytest path/test_module.py::TestClass

Single test function

pytest path/test_module.py::test_function

All tests in a module

pytest path/test_module.py

All tests in a directory

pytest path

Tests matching a name pattern

pytest -k pattern

Tests by marker

Covered in Chapter 6, Markers.

We’ve used everything but pattern and marker ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Testing with pytest

Python Testing with pytest

Brian Okken

Publisher Resources

ISBN: 9781680509427Errata Page