Brian Okken
Finding the top pytest plugins
What are the top downloaded pytest plugins? I want to know this. And I’d like the answer updated regularly. So today I decided to write a script to do that for me. Grab data Let’s start with Top PyPI Packages from Hugo van Kemenade. This list is “A monthly dump of the 8,000 most-downloaded packages from PyPI.” Perfect. Parse Now: Filter for “pytest” in the package name Remove “pytest” itself....
pytest 8 is here
pytest 8.0.0 was released on 17-Jan-2024, and I’m pretty excited about it. I’m not going to cover all fo the changes, I’ll just highlight a few. For full set of changes, see the pytest changelog: Changes in 8.0.0rc1 Changes in 8.0.0rc2 Changes in 8.0.0 Version Compatibility Dropped support for Python 3.7, as it reached EOL last June. Features and Improvements Improved Diffs Improved diffs that pytest prints when an assertion fails, including:...
Testing argparse Applications
I was asked recently about how to test the argument parsing bit of an application that used argparse. argparse is a built in Python library for dealing with parsing command line arguments for command line interfaces, CLI’s. You know, like git clone <repo address>. git is the application. <repo address> is a command line argument. clone is a sub-command. Well, that might be a bad example, as I’m not going to use subcommands in my example, but lots of this still applies, even if you are using subcommands....
pytest slow order
I received a question the other day about combining the notion of marking slow tests and ordering them to run the slow tests first. This post describes a bit of background and a solution to the problem. @pytest.mark.slow It’s possible to mark slow tests with @pytest.mark.slow and then either run or skip the slow tests. To run slow tests: pytest -m slow To skip slow tests: pytest -m "not slow" With the pytest-skip-slow plugin, you can:...
Upgrading to Python 3.12 and my battle with virtualenv cache
edited Oct 3, 2023 with a new fix and a new understanding of the problem Initial title was … Python 3.12 + "AttributeError: module ‘pkgutil’ has no attribute ‘ImpImporter’. Did you mean: ‘zipimporter’?" This is a tale of upgrading Python 3.12 I ran into this error while I was trying to update a project to test on Python 3.12: ... File "/Users/okken/Library/Application Support/virtualenv/wheel/house/pip-23.0.1-py3-none-any.whl/pip/_internal/metadata/importlib/_envs.py", line 123, in _find_eggs_in_zip from pip....
pytest Primary Power Course Is Ready
Everything you need to get started with pytest and use it effectively. Learn about: Test Functions Structure functions effectively Fixtures setup, teardown, and so much more Builtin Fixtures many common testing tasks are pre-built and ready to use Parametrization turn one test into many test cases Markers Builtin markers provided by pytest Custom markers for test selection Combining markers and fixtures to alter pytest behavior Available now Grab pytest Primary Power now, and start testing more effectively today....
pytest Course
Introducing “The Complete pytest Course” series. This is a video course series based on “Python Testing with pytest, 2nd edition”. Basically, the bundle includes all courses in the series, available as he videos get completed, and includes a private discussion group and repo. See The Complete pytest Course for more info.
Sharing is Caring - Sharing pytest Fixtures - PyCascades 2023
Slides and code and such for a talk for PyCascades 2023. Talk page: Sharing is Caring - Sharing pytest Fixtures Summary: pytest rocks, obviously. When people start using pytest as a team, they often come up with cool fixtures that would be great to share across projects. In fact, many great Python packages come pre-loaded with pytest fixtures. This talk describes how easy it is to share fixtures using the pytest plugin model....
pytest tips and tricks
This is a set of tips/tricks for learning and using pytest. I’ll probably build on the list, so feel free to share with me items you think should be in the list. Many items really deserve more explanation, and maybe full posts. Let me know if there’s something you’d like more in depth discussion of. Note: I’m not numbering these, because I don’t want to keep track of order. Also, this is more of a brain dump, and not a prioritized list....
Fixing Circular Imports in Python with Protocol
The problem started when I had two classes that needed to talk to each other. Sometimes, classes need to talk to each other in both directions. The following example is made up, but mostly behaves like the original problem. Let’s say I have a Director and an Actor. The Director tells the Actor to do_action(). In order to do the action, the Actor needs to get_data() from the Director. Here’s our director....