Buy new:
$39.49
FREE delivery: Friday, Dec 15
Ships from: Amazon.com
Sold by: Amazon.com
List Price: $45.95 Details

The List Price is the suggested retail price of a new product as provided by a manufacturer, supplier, or seller. Except for books, Amazon will display a List Price if the product was purchased by customers on Amazon or offered by other retailers at or above the List Price in at least the past 90 days. List prices may not necessarily reflect the product's prevailing market price.
Learn more
Save: $6.46 (14%)
FREE Returns
Return this item for free
  • Free returns are available for the shipping address you chose. You can return the item for any reason in new and unused condition: no shipping charges
  • Learn more about free returns.
FREE delivery Friday, December 15. Order within 3 hrs 27 mins
Arrives before Christmas
In Stock
$$39.49 () Includes selected options. Includes initial monthly payment and selected options. Details
Price
Subtotal
$$39.49
Subtotal
Initial payment breakdown
Shipping cost, delivery date, and order total (including tax) shown at checkout.
$3.99 delivery December 18 - 22. Details
Or fastest delivery December 14 - 19. Details
Arrives before Christmas
Used: Good | Details
Sold by HPB-Red
Condition: Used: Good
Comment: Connecting readers with great books since 1972! Used textbooks may not include companion materials such as access codes, etc. May have some wear or writing/highlighting. We ship orders daily and Customer Service is our top priority!
Access codes and supplements are not guaranteed with used items.
Loading your book clubs
There was a problem loading your book clubs. Please try again.
Not in a club? Learn more
Amazon book clubs early access

Join or create book clubs

Choose books together

Track your books
Bring your club to Amazon Book Clubs, start a new book club and invite your friends to join, or find a club that’s right for you for free.
Kindle app logo image

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.

QR code to download the Kindle App

Follow the author

Something went wrong. Please try your request again later.

Python Testing with pytest: Simple, Rapid, Effective, and Scalable 2nd Edition

4.5 4.5 out of 5 stars 68 ratings

Price
New from Used from
Kindle
Paperback
$39.49
$35.49 $31.61
{"desktop_buybox_group_1":[{"displayPrice":"$39.49","priceAmount":39.49,"currencySymbol":"$","integerValue":"39","decimalSeparator":".","fractionalValue":"49","symbolPosition":"left","hasSpace":false,"showFractionalPartIfEmpty":true,"offerListingId":"q%2FCbyVeQ%2BuAlfzzCY2bQKmTLJJcE5f6xZc1LtS6t8ADM7yA959fu0uSBDPdbPdCZgsZZmrNtja4NWqf2rAk2RQwtRJ72oOCKkdAelz%2BBRnenmYjqPPsQcpYoM32cf8BB5TEz9hwM9BaKdPvndjBbZw%3D%3D","locale":"en-US","buyingOptionType":"NEW","aapiBuyingOptionIndex":0}, {"displayPrice":"$33.17","priceAmount":33.17,"currencySymbol":"$","integerValue":"33","decimalSeparator":".","fractionalValue":"17","symbolPosition":"left","hasSpace":false,"showFractionalPartIfEmpty":true,"offerListingId":"q%2FCbyVeQ%2BuAlfzzCY2bQKmTLJJcE5f6xhVJGY0l44mjNx3OT4sIShupDxASPbhDtyRHmawGo3o6rg42wMlUVYJsoSEPZbep1DLZGMHlaYPwuTgW52SaFCNl8DVdDGcONIOpCcclFKYMy7g5BxkO%2B1QrHtuIIa%2BPOXA4fb8dQDQojTP008h6dwZdjPa%2FJ0p3F","locale":"en-US","buyingOptionType":"USED","aapiBuyingOptionIndex":1}]}

Purchase options and add-ons


Amazon First Reads | Editors' picks at exclusive prices

Frequently bought together

$39.49
Get it as soon as Friday, Dec 15
In Stock
Ships from and sold by Amazon.com.
+
$39.95
Ships from and sold by Amazon.com.
+
$43.49
Get it as soon as Monday, Dec 18
Only 2 left in stock (more on the way).
Ships from and sold by Amazon.com.
Total price:
To see our price, add these items to your cart.
Details
Added to Cart
Some of these items ship sooner than the others.
Choose items to buy together.

From the brand


From the Publisher

Python Testing with pytest

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

Brian Okken is the host of the Test & Code podcast, and co-host of the Python Bytes podcast. He's also a lead software engineer.

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
  • Customer Reviews:
    4.5 4.5 out of 5 stars 68 ratings

Important information

To report an issue with this product, click here.

About the author

Follow authors to get new release updates, plus improved recommendations.
Brief content visible, double tap to read full content.
Full content visible, double tap to read brief content.

Discover more of the author’s books, see similar authors, read author blogs and more

Customer reviews

4.5 out of 5 stars
4.5 out of 5
68 global ratings

Submit a report

A few common reasons customers report reviews:
  • Harassment, profanity
  • Spam, advertisement, promotions
  • Given in exchange for cash, discounts
When we get your report, we'll check if the review meets our Community guidelines. If it doesn't, we'll remove it.
Sorry we couldn't load the review
Thank you for your feedback

Sorry, there was an error

Please try again later.

Top reviews from the United States

Reviewed in the United States on December 2, 2023
Customer image
5.0 out of 5 stars must have lecture for professional python developers
Reviewed in the United States on December 2, 2023
The author got me from the first moment, everything is very well explained, the examples are fantastic and after reading it I felt much more confident to approach the test stage in my work.
Images in this review
Customer image
Customer image
Reviewed in the United States on December 29, 2022
One person found this helpful
Report
Reviewed in the United States on October 29, 2022
Reviewed in the United States on June 26, 2022
2 people found this helpful
Report
Reviewed in the United States on March 17, 2022
4 people found this helpful
Report
Reviewed in the United States on December 16, 2022
Customer image
3.0 out of 5 stars Does not fill in pytest's documentation gaps as I would wish
Reviewed in the United States on December 16, 2022
I was looking for how to get the logging module to work with my tests. Logging is an important way for me (and I would think most) to understand why my tests on example data are not working the way I want. The attached picture is all the book mentions about the subject - the one line that says "caplog--captures output written with the logging package".

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.
Images in this review
Customer image
Customer image
3 people found this helpful
Report
Reviewed in the United States on April 8, 2022
4 people found this helpful
Report

Top reviews from other countries

Hugh Smith
5.0 out of 5 stars The only pytest book you need.
Reviewed in the United Kingdom on July 27, 2023