pytest fixtures nuts and bolts - revisited
A series on pytest fixtures gets updated
A collection of 28 Posts
Brett Cannon recently released an article explaining Python 3.14's new t-strings. This article has pytest versions of the code from Brett's article.
I noticed a fun post by Ned Batchelder called "Testing some tidbits". The post looks at different ways to see if a string has only 0 or 1 in it. I'm expanding on that with some pytest code to test the different ways.
This is the first iteration that implements ’expect’ as a fixture.
This is really the third attempt at an ’expect()’ implementation that …
Further thoughts on the way to pytest-check
The start of thinking that led to pytest-check
Fixtures can only use other fixtures with equal or wider scope
We can use conftest.py to define fixtures that can be used by multiple files and still only run once per session
Running fixtures (and the tests that depend on them) multiple times with different values
Startup and teardown can surround functions, classes, modules/files, directories, or the entire test session.
If you want to apply a fixture to all tests in a class or file
You can run some doctests from pytest, according to the documentation.
However, it can be a bit fiddly.
With my examples of putting doctests in text files, if I …
To show how pytest handles unittests, here’s a sample run of pytest on the simple unittests I wrote in the unittest introduction:
$ pytest …
I think of pytest as the run-anything, no boilerplate, no required api, use-this-unless-you-have-a-reason-not-to test framework.
This is really where testing …