Python Testing with pytest (Pragmatic Bookshelf)

PragmaticBookshelf
Do less work when testing your Python code, but be just as expressive, elegant, and readable. The pytest testing framework helps you write tests quickly and keep them readable and maintainable—with no boilerplate code. Using a robust fixture model, write small tests or scale up to testing for applications, packages, and libraries.

Brian Okken @brianokken

Edited by Katharine Dvorak @katied

Do less work when testing your Python code, but be just as expressive, elegant, and readable. The pytest testing framework helps you write tests quickly and keep them readable and maintainable—with no boilerplate code. Using a robust fixture model, write small tests or scale up to testing for applications, packages, and libraries.

Get up to speed quickly on this powerful tool with step-by-step instructions and sample code. Add testing features and speed up test times by distributing tests across multiple processors. Test error conditions and corner cases with expected exception testing, and use one test to run many test cases with parameterized testing. Extend pytest with plugins, connect it to continuous integration systems, and use it in tandem with tox, mock, coverage, unittest, and doctest.

Write simple, maintainable tests that elegantly express what you’re testing and why.


“This book is the missing chapter absent from every comprehensive Python book.”

– Frank Ruiz, principal site reliability engineer, Box, Inc.


  • Full details: Search
  • View this book’s portal and details on how to post errata and suggestions here.

Don’t forget you can get 35% off with your Devtalk discount! Just use the coupon code “devtalk.com" at checkout :+1:

2 1075 0

Latest Threads About This Book Top

josealobato
Reading this chapter several times I’m trying to understand how to properly run test against the code of a package. It looks to me that ...
0 679 1
New
M-110
In the downloadable code in the file: \code\tasks_proj\src\tasks\ tasksdb_tinydb.py On line 66, the function’s return mistakenly says i...
0 843 0
New
alter
Chapter 6, Specifying Test Directory Locations 2 instances of ‘testspaths’ should be replaced with ‘testpaths’ Loc 6256 and 6289 in Kin...
2 880 0
New
brianokken
Pin the tinydb version to 3.15.1. The API changed in the 4.x series of tinydb. However, the change doesn’t affect you learning pytest. ...
2 1043 0
New
johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
4 1228 1
New
brianokken
Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not decl...
2 1373 2
New
brianokken
pytest has changed how hook functions access configuration since the book was published. Following is the correct code for recent version...
2 1023 0
New
telemachus
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks” While running the smoke tests in Chapter 2, I get these...
5 2069 1
New
johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
5 3517 1
New
PragmaticBookshelf
Do less work when testing your Python code, but be just as expressive, elegant, and readable. The pytest testing framework helps you writ...
2 1075 0
New

Most Active This Week Top

Most Active This Month Top

Most Active This Year Top

Most Active Last Three Years Top

Most Active Over Three Years Top

johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
5 3517 1
New
telemachus
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks” While running the smoke tests in Chapter 2, I get these...
5 2069 1
New
PragmaticBookshelf
Do less work when testing your Python code, but be just as expressive, elegant, and readable. The pytest testing framework helps you writ...
2 1075 0
New
brianokken
Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not decl...
2 1373 2
New
johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
4 1228 1
New
brianokken
Pin the tinydb version to 3.15.1. The API changed in the 4.x series of tinydb. However, the change doesn’t affect you learning pytest. ...
2 1043 0
New
brianokken
pytest has changed how hook functions access configuration since the book was published. Following is the correct code for recent version...
2 1023 0
New
alter
Chapter 6, Specifying Test Directory Locations 2 instances of ‘testspaths’ should be replaced with ‘testpaths’ Loc 6256 and 6289 in Kin...
2 880 0
New
M-110
In the downloadable code in the file: \code\tasks_proj\src\tasks\ tasksdb_tinydb.py On line 66, the function’s return mistakenly says i...
0 843 0
New
josealobato
Reading this chapter several times I’m trying to understand how to properly run test against the code of a package. It looks to me that ...
0 679 1
New

Book Info

Publisher: Pragmatic Bookshelf

Are you this book's author? To be notified of all posts made about it, sign up an account then click here, then select 'watching' from the bell icon in the top right corner.

Get money off!

The Pragmatic Bookshelf

35% off any eBook

Simply use coupon code "devtalk.com" at checkout. See full details here.