Change8

9.1.0

Breaking Changes
📦 pytestView on GitHub →
1 breaking5 features9 deprecations🔧 15 symbols

Summary

Pytest 9.1.0 introduces imperative fixture registration and new CLI options for reporting and warning limits. This release also contains several deprecations targeting internal APIs and older usage patterns, scheduled for removal in pytest 10.

⚠️ Breaking Changes

  • When using --doctest-modules, autouse fixtures with scope 'module', 'package', or 'session' defined inline in Python test modules (not plugins or conftests) may now execute twice. Move fixture definitions to a conftest.py file if this behavior is undesirable.

Migration Steps

  1. If autouse fixtures defined inline in test modules execute twice when using --doctest-modules, move the fixture definition to a conftest.py file.
  2. For class-scoped fixtures defined as instance methods, add the @classmethod decorator.
  3. When requesting fixtures during teardown, ensure the fixture was already requested during setup/execution, or prepare for an error in pytest 10.
  4. Use collections.abc.Collection iterables (like lists or tuples) for the argvalues parameter in @pytest.mark.parametrize.
  5. Access configuration values using config.getini() instead of config.inicfg.
  6. When registering fixtures, use the node parameter instead of baseid or nodeid.
  7. Use pytest.main() instead of pytest.console_main() for programmatic execution.
  8. If using the --pastebin option, switch to the external plugin 'pytest-pastebin'.

✨ New Features

  • Added pytest.register_fixture() to register fixtures using an imperative interface, intended for plugins.
  • Added --report-chars long CLI option.
  • Added --max-warnings command-line option and max_warnings configuration option to fail the run if warning count exceeds a threshold.
  • Added the assertion_text_diff_style configuration option to render string equality failures with Left:/Right: blocks instead of ndiff output.
  • Added support for ~datetime.datetime and ~datetime.timedelta comparisons with pytest.approx, requiring an explicit ~datetime.timedelta for tolerance.

Affected Symbols

⚡ Deprecations

  • Class-scoped fixtures defined as instance methods (without @classmethod) are deprecated; use @classmethod instead.
  • Calling request.getfixturevalue() during teardown to request a fixture that was not already requested is deprecated and will raise an error in pytest 10.
  • Using non-collections.abc.Collection iterables (like generators or iterators) for the argvalues parameter in @pytest.mark.parametrize and metafunc.parametrize is deprecated.
  • The private config.inicfg attribute is deprecated; use config.getini() instead.
  • Passing baseid to ~pytest.FixtureDef or nodeid strings to fixture registration APIs is deprecated; use the node parameter instead.
  • Configuring hooks using markers, deprecated since pytest 7.2, is scheduled for removal in pytest 10.
  • The --pastebin option is deprecated; use the external plugin 'pytest-pastebin' instead.
  • The private FixtureDef.has_location attribute is deprecated and will be removed in pytest 10.
  • pytest.console_main is deprecated and will be removed in pytest 10; use pytest.main instead.