small medium large xlarge

Python Testing with pytest

May 24, 2017

The first telegraph line was inaugurated on this day way back in 1844, when Samuel Morse sent the message "What hath God wrought." The message was received intact, and thus their test passed.

One hundred and seventy-three years later, testing can be a little more complicated than that. But it doesn't have to be hard. Do less work when testing your Python code, but be just as expressive, just as elegant, and just as readable, using Python Testing with pytest, now in beta from

Come and get it!

Python Testing with pytest: Simple, Rapid, Effective, and Scalable

For Python-based projects, pytest is the undeniable choice to test your code if you're looking for a full-featured, API-independent, flexible, and extensible testing framework. With a full-bodied fixture model that is unmatched in any other tool, the pytest framework gives you powerful features such as assert rewriting and plug-in capability—with no boilerplate code.

With simple step-by-step instructions and sample code, this book gets you up to speed quickly on this easy-to-learn and robust tool. Write short, maintainable tests that elegantly express what you're testing. Add powerful testing features and still speed up test times by distributing tests across multiple processors and running tests in parallel. Use the built-in assert statements to reduce false test failures by separating setup and test failures. 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.

Now in beta from

Upcoming Author Appearances

  • 2017-05-25 Diana Larsen,
    XP2017, Cologne, Germany
  • 2017-06-06 Chris Adamson,
    CocoaConf Next Door, San Jose
  • 2017-06-07 Chris Adamson,
    CocoaConf Next Door, San Jose
  • 2017-06-07 Jeff Kelley,
    Code PaLOUsa, Louisville, KY
  • 2017-06-08 Chris Adamson,
    CocoaConf Next Door, San Jose
  • 2017-06-09 Jeff Kelley,
    Beer City Code, Grand Rapids, MI
  • 2017-06-20 Ian Dees,
    Open Source Bridge, Portland, OR
  • 2017-06-23 Andrew Hunt,
    DC Full Stack Conference
  • Did You Know?

    You can synch your ebooks amongst your devices via Dropbox, including updates! Just login to your account on, edit your profile, and connect your dropbox account. See our FAQ for details.

    Don't Get Left Out

    Are your friends jealous that you get these spiffy email newsletters and they don't? Clue them in that all they need to do is create an account on (email address and password is all it takes) and select the checkbox to receive newsletters.

    Are you following us on Twitter and/or Facebook? Here's where you can find us and keep up with the latest news and commentary, and occasional discounts:

    Tell your friends! Tweet this

    Follow us on Twitter: pragprog</a>, <a href="">pragpub, Andy Hunt @PragmaticAndy.

    Coming Soon:

    • Domain Modeling Made Functional: Tackle Software Complexity with Domain-Driven Design and F#
    • Node.js 8 the Right Way: Practical, Server-Side JavaScript That Scales
    • Scalable Cloud Ops with Fugue (in print)

    Recently Released:

    Thanks for your continued support,

    Andy Hunt
    Publisher, Pragmatic Bookshelf

    Books • eBooks • PragPub Magazine • Audiobooks and Screencasts