Python Testing with pytest (PragProg)

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 Likes