Python testing tool makes strides to shed old dependencies as v7.0 rises

pytest 7.0

The team responsible for Python testing framework pytest has steered 960 commit strong version 7.0 across the finish line, cleaning up the project and its error notifications in the process and making room for a bit more customisation.

Once upgraded to the new release, developers for instance have the option to add colours to custom log levels on the command-line interface log, and 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 to identify the pytest version used on a system, which can help to declare compatible testing steps for different versions.

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 was simplified, so that they are now “ordered by definition order in more cases”. Pytest also started to export additional types of objects used in pytest’s API, meaning they can be utilised for type annotations. Direct construction or subclassing them however isn’t an option and will lead to warnings for now.

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

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, [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, which include the py.path.local arguments for hooks, using unittest.SkipTest{.interpreted-text role="class"} to skip collection of tests during the collection phase, and constructing various classes directly, can be found in the release notes.