Get introduced to writing tests in Python with pytest

Hi all! Recently at work, I’ve been diving deep into test-driven development (TDD) and writing unit tests in code. This post is a collection of some of what I’ve been reading to give you a deep dive into pytest, a Python testing framework.

I suggest starting with this post. It gives a simple introduction to pytest, how it works, and does an overview of most important concepts:

To take it a step further, this post is a deep dive into one of the more unique parts of pytest: fixtures. This post looks at fixtures and breaks them down into smaller pieces to give an idea of how they all work:

Lastly, this post provides more of the “why” context for pytest versus other Python testing frameworks. It also provides some seasoned experience on writing tests generally that I found lacking in other articles:

For bonus points, this post gives some pointers to different pytest plugins. One of the advantages to pytest is the diverse plugin community that is built up around it. To use pytest effectively, you will want to embrace using plugins! Check out this article for some popular ones:

If you want to drop a few dollars, I also suggest Python Testing with pytest: Simple, Rapid, Effective, and Scalable by Brian Okken. I’ve been working through a copy of this book and there’s some great content there too.

I hope some folks find this useful to begin learning more about writing testable code!