Dealing with fixtures is one of the areas where pytest really shines.
This is rather an incredible understatement.

The xunit style of test fixtures that is used in both unittest and nose is of course supported with with pytest. And pytest rocks at this.

But there is another way to deal with fixtures. It’s to think of fixtures as a set of resources that need to be set up before a test starts, and cleaned up after. Test functions, methods, classes, name which fixtures they need. This way, fixtures aren’t set up for tests that don’t need them.

This focus on the fixture as a modular resource, possibly set up once for many tests, or perhaps for each test, is a really cool way to treat fixtures.
However, it took me a while to really get my head around it.

Truth. I don’t think one post will do it justice.
So, I’ll take a bit at a time, and try to cover it in a way that I can express how cool I think pytest fixtures are, and hopefully completely enough that you can use them effectively.

It’s not complicated to use. It’s really quite simple.
But it’s different enough from what I was used to that I think a series of posts would be best.

Originally, this was a 4 post series, with the last post being super long. In July of 2025 I split it up into more posts, each mostly covering one topic. It’s not really longer, it’s just that each post is shorter now, and hopefully this will make a better reference. The downside is the “other posts in the series” note is now quite long. So I’m sticking it at the end of the posts.