Enjoy fast, free delivery, exclusive deals, and award-winning movies & TV shows with Prime
Try Prime
and start saving today with fast, free delivery
Amazon Prime includes:
Fast, FREE Delivery is available to Prime members. To join, select "Try Amazon Prime and start saving today with Fast, FREE Delivery" below the Add to Cart button.
Amazon Prime members enjoy:- Cardmembers earn 5% Back at Amazon.com with a Prime Credit Card.
- Unlimited Free Two-Day Delivery
- Instant streaming of thousands of movies and TV episodes with Prime Video
- A Kindle book to borrow for free each month - with no due dates
- Listen to over 2 million songs and hundreds of playlists
- Unlimited photo storage with anywhere access
Important: Your credit card will NOT be charged when you start your free trial or if you cancel during the trial period. If you're happy with Amazon Prime, do nothing. At the end of the free trial, your membership will automatically upgrade to a monthly membership.
Buy new:
$39.49$39.49
FREE delivery:
Friday, Dec 15
Ships from: Amazon.com Sold by: Amazon.com
Buy used: $33.17
Download the free Kindle app and start reading Kindle books instantly on your smartphone, tablet, or computer - no Kindle device required.
Read instantly on your browser with Kindle for Web.
Using your mobile phone camera - scan the code below and download the Kindle app.
Python Testing with pytest: Simple, Rapid, Effective, and Scalable 2nd Edition
| Price | New from | Used from |
- Kindle
$28.99 Read with our free app - Paperback
$33.17 - $39.496 Used from $31.61 25 New from $35.49
Purchase options and add-ons
Test applications, packages, and libraries large and small with pytest, Python's most powerful testing framework. pytest helps you write tests quickly and keep them readable and maintainable. In this fully revised edition, explore pytest's superpowers - simple asserts, fixtures, parametrization, markers, and plugins - while creating simple tests and test suites against a small database application. Using a robust yet simple fixture model, it's just as easy to write small tests with pytest as it is to scale up to complex functional testing. This book shows you how.
pytest is undeniably the best choice for testing Python projects. It's a full-featured, flexible, and extensible testing framework. pytest's fixture model allows you to share test data and setup procedures across multiple layers of tests. The pytest framework gives you powerful features such as assert rewriting, parametrization, markers, plugins, parallel test execution, and clear test failure reporting - 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 yet powerful tool. Write short, maintainable tests that elegantly express what you're testing. Speed up test times by distributing tests across multiple processors and running tests in parallel. Use Python's builtin assert statements instead of awkward assert helper functions to make your tests more readable. Move setup code out of tests and into fixtures to separate setup failures from 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, and even existing unittest tests.
Write simple, maintainable tests quickly with pytest.
What You Need:
The examples in this book were written using Python 3.10 and pytest 7. pytest 7 supports Python 3.5 and above.
- ISBN-101680508601
- ISBN-13978-1680508604
- Edition2nd
- PublisherPragmatic Bookshelf
- Publication date
2022
March 29
- Language
EN
English
- Dimensions
7.5 x 0.6 x 9.3
inches
- Length
274
Pages
Frequently bought together

Similar items that may ship from close to you
From the brand
-
The Pragmatic Bookshelf
By Developers, for Developers
-
-
The Pragmatic Programmers publishes hands-on, practical books on classic and cutting-edge software development and engineering management topics. We help professionals solve real-world problems, hone their skills, and advance their careers.
From the Publisher
From the Preface
Why a Second Edition?
Both Python and pytest have changed since the first edition of this book was published in 2017. There have been updates to pytest that are now reflected in the book:
- New builtin fixtures
- New flags
- The addition of package scope fixtures
There have also been updates to Python that are reflected in the book:
- The adoption of f-strings and pathlib
- The addition of dataclasses
Also, since publication of the first edition, I have taught many, many people about pytest, and I think I’ve learned how to be a better teacher. The second edition not only expands on what is covered in the first edition—it grew from 7 to 16 chapters!—but also it presents the material in what I think is a more gradual, digestible manner.
So what’s in all of these new chapters?
- More on parametrization, markers, coverage, mocking, tox and continuous integration, and third-party plugins. All of these topics were covered in the first edition, but in this edition I expand that coverage. I pulled the discussion of parametrization into its own chapter and added a discussion of advanced parametrization techniques. I delve more deeply into markers and include an example of how to pass data from markers to fixtures (which is super cool). I also take you on a deeper dive into test coverage, mocking, and CI, and using and building your own plugins to extend pytest’s capabilities.
- A discussion of test strategy. Feedback from the first edition was that the book was great for the mechanics of how to use pytest, but the “What test do I write?” information was a bit lacking. The new Chapter 7, Strategy is a push in the right direction of what tests to write. A complete treatment of test strategy would be a book in itself; however, this chapter will get you started.
- Information about the Python search path. A lot of readers reached out to me asking about how to get their tests to see their test code, and the first edition didn’t cover it. The project in this book, Cards, doesn’t have that problem because it’s an installed Python package. However, lots of user projects are applications or scripts or lots of other things that are not installed packages. This chapter offers a focused look at the problem and provides some solutions.
I consolidated the information about debugging test failures into a chapter of its own. In the last edition, this information was spread all throughout the book. It is my hope that when you are faced with a deadline and a failing test suite, bringing this information together into one chapter will help you figure out an answer quickly and ease some stress.
Finally, the example project changed. The first edition used a project called Tasks to illustrate how to use pytest. Now it’s called Cards. Here’s why:
- It’s easier to say out loud. (Try it. Say “tasks” three times, then “cards” three times. Right?)
- The new project itself is different because it uses Typer instead of Click for command-line functionality. Typer code is easier to read.
- The project also uses Rich for formatting the output. Rich didn’t exist (neither did Typer) when the first edition was written.
The code examples have also been simplified. The directory structure of the first edition code examples followed a progression of a possible test directory within a project, with most of the project removed. Seriously, I think it made sense to me at the time. In this edition, there is a project in its own directory, cards_proj, with no tests. Then, each of the chapters have test code (if appropriate) that either work on the one project or on some local code. Trust me, I think you’ll agree that it’s way easier to follow along now.
Editorial Reviews
About the Author
Product details
- Publisher : Pragmatic Bookshelf; 2nd edition (March 29, 2022)
- Language : English
- Paperback : 274 pages
- ISBN-10 : 1680508601
- ISBN-13 : 978-1680508604
- Item Weight : 1.05 pounds
- Dimensions : 7.5 x 0.58 x 9.25 inches
- Best Sellers Rank: #728,843 in Books (See Top 100 in Books)
- #194 in Software Testing
- #679 in Python Programming
- #2,649 in Internet & Social Media
- Customer Reviews:
Important information
To report an issue with this product, click here.
About the author

Discover more of the author’s books, see similar authors, read author blogs and more
Customer reviews
Customer Reviews, including Product Star Ratings help customers to learn more about the product and decide whether it is the right product for them.
To calculate the overall star rating and percentage breakdown by star, we don’t use a simple average. Instead, our system considers things like how recent a review is and if the reviewer bought the item on Amazon. It also analyzed reviews to verify trustworthiness.
Learn more how customers reviews work on AmazonReviews with images
Submit a report
- Harassment, profanity
- Spam, advertisement, promotions
- Given in exchange for cash, discounts
Sorry, there was an error
Please try again later.-
Top reviews
Top reviews from the United States
There was a problem filtering reviews right now. Please try again later.
Reviewed in the United States on December 2, 2023
The pytest documentation was scant on the subject, and the book was even more sparce. I still don't know how to use the caplog fixture, but at least the pytest site mentioned some flags I could put in there.
This book seems to be but a short summary of the pytest official documentation. I wish it were more.
Reviewed in the United States on December 16, 2022
The pytest documentation was scant on the subject, and the book was even more sparce. I still don't know how to use the caplog fixture, but at least the pytest site mentioned some flags I could put in there.
This book seems to be but a short summary of the pytest official documentation. I wish it were more.










