From Slop to Software
Leveraging Pytest & Friends
This book shows how to design tests that survive change.
You learn how to choose test boundaries, structure test suites, control nondeterminism, and integrate testing into everyday development and CI workflows. The emphasis is not on tricks or magic APIs, but on habits that make tests predictable and explainable.
An Overview
We start with projects to understand why testing matters and how tests fail when the structure is wrong. Then we move through pytest fundamentals, fixtures, parametrization, and marks, and then into configuration that keeps behavior consistent across machines.
From there, the book covers mocking and monkeypatching as boundary tools rather than defaults, shows how to think about coverage without gaming metrics, and explores TDD as a tool for successful coding with AI.
Later chapters focus on CI with GitHub Actions, linting and hooks with Ruff and pre-commit, type checking, testing inside notebooks, and finally, how AI agents interact with test suites.
This book is for
Python developers who want to write better code
Data scientists and ML engineers who deal with instability, randomness, and evolving data
AI practitioners who want to guide slop to software
This book covers some tools you might have heard of... and some that you might not have:
uv
pytest
coverage
ruff
prek
zizmor
GitHub Actions
hypothesis
ty
mock
monkeypatch
pdb
doctest
This book offers practical guidance on writing tests in Python and covers relevant libraries such as unittest and pytest for doing so. For anyone working with notebooks, an entire chapter is dedicated to testing using ipytest in Jupyter.
This book is a must have for any Python practitioner looking to improve the quality of their code.
Great book, great material and always learning new stuff thanks to you!
I’ve read a few books on Python testing, but this is easily the most modern and comprehensive guide I’ve encountered. I'm privileged to have reviewed an early copy this book. If you’re looking to master Python testing in 2026, this is the one.
I would recommend this book to others
FAQ section
You've got questions. We've got answers.
I've coded Python for over 25 years. I also wrote the Python coverage plugin for ... emacs.
I've taught week-long testing courses for some of the biggest companies in the world.
Many companies offer reimbursement for these types of purchases. If they don't, they should. Going through this book and applying what you learn would be one of the most cost-effective uses of time for many of the folks I work with. Especially given the current state of development.
If "others" is referring to Brian Okken's book, it's awesome. You should buy it and read it too. (I was a reviewer for both versions of his books.)
This book is based on my years of experience as a software developer and data scientist, as well as my decade of teaching software development and testing to some of the largest companies (and space agencies) in the world.
The content is based on real-world experience.
It also covers more than just pytest.
It is probably the only testing book to cover tools like uv, prek, ty, and more.
I'm glad you asked. I've worked with some of the largest software, hardware, media, energy, finance, space agencies, and universities in the world.
I would love to take a call to discuss how to help your team apply the time-tested testing strategies using the modern libraries in this book.