From Slop to Software

Effective Testing

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.

What's Inside the Book

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.

Who this Book is For

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

Modern Tools for Python

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

Phil Q.

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.

Gonzalo P

Great book, great material and always learning new stuff thanks to you!

Ricky M

I highly recommend this book to all python (AI) coders

Nasiru O

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.

Perry R.

I would recommend this book to others

Richard A.

I found explanations and examples quite clear, and will recommend it for someone seeking to learn about testing.

FAQ section

Frequently asked questions

You've got questions. We've got answers.

Why should I trust you?

I've coded Python for over 25 years. I also wrote the Python coverage plugin for ... emacs.

What do you know about testing?

I've taught week-long testing courses for some of the biggest companies in the world.

Can I get this reimbursed?

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.

What's different between this book and others?

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.

Can you help my team apply this?

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.

Three Options

Three ways to learn

Just the Book

  • 300+ pages of the most comprehensive guide to modern testing with Python.

  • $49

Book & Video

  • Book

  • Video course on testing

  • $79

Book, Video, & Consult

  • Book

  • Video Course

  • Zoom consult on your specific testing needs

  • $399