2 min

Tags in this article

, ,

The new version of pytest brings a range of advantages

The pytest team team has released version 7.0 of the Python testing framework. They did so with a force of 960 commits behind them. The new version cleans up the project and its error notifications. It also facilitates more customisation.

Once upgraded to the new release, developers will have the option to add colours to custom log levels on the command-line interface log. They can also adapt the pygments theme they use via new environment variables PYTEST_THEME and PYTEST_THEME_MODE. There’s also a new version-tuple{.interpreted-text role="ref"} attribute. This helps to identify the pytest version used on a system. That in turn can help to declare compatible testing steps for different versions.

Freeing pytest from its old py dependencies

One of the bigger chunks of changes present in the release has to do with the project trying to free itself from py dependencies. As a result, pytest 7.0 comes with new function cache.mkdir() <pytest.Cache.mkdir>{.interpreted-text role="meth"}, a paths type for parser.addini() <pytest.Parser.addini>{.interpreted-text role="meth"}, and new arguments for a number of hooks, which are similar to existing py.path.local equivalents but using path instead.

The order of tests has been simplified,. They are now “ordered by definition order in more cases”. Pytest also started to export additional types of objects used in pytest’s API. This means they can be utilised for type annotations. However, direct construction or subclassing them isn’t an option and will lead to warnings.

Developers who previously had issues importing libraries while using features like pickle or dataclasses should run into fewer crashes with v7. This is because the corresponding functionality has been reworked. More detailed error messages and improved assertion messages are also hoped to help with the overall experience.

Teams looking to update their setup should be aware of the list of breaking changes and deprecations coming with version 7.0. Amongst other things, --version learned to write version information to stdout instead of stderr to facilitate the creation of automation tooling. Also,[reportinfo()]{.title-ref} sports an expanded return value type, and the pytest.Instance collector type has been dropped.

A full list of removals and deprecations can be found in the release notes.