Pytest 9.1.0 Update: Key Changes for QA Automation

TL;DR

  • --doctest-modules users: autouse fixtures might run twice; consider moving them to conftest.py.
  • Several key deprecations, including request.getfixturevalue() during teardown and non-Collection iterables in parametrize.
  • New --max-warnings option to fail runs based on warning count, enhancing test stability.

Key Changes

Pytest 9.1.0, released on 2026-06-13, introduces a mix of breaking changes, deprecations, and new features relevant for test automation engineers. This minor update focuses on refining fixture behavior, improving configuration, and providing more control over test execution.

Removals and Breaking Changes: The most notable breaking change affects users of --doctest-modules. Autouse fixtures with module, package, or session scope, defined inline in test modules, may now execute twice. To avoid this, move such fixture definitions to a conftest.py file. This change stems from improvements in pytest’s fixture implementation and how DoctestModule collects fixtures.

Deprecations: Pytest 9.1.0 introduces several deprecations, signaling upcoming changes in pytest 10:

  • Fixture Management: Calling request.getfixturevalue() during teardown for an unrequested fixture is deprecated. Also, class-scoped fixtures defined as instance methods (without @classmethod) are deprecated due to unexpected behavior. For more on fixtures, see our pytest-tutorial-python-testing.
  • Parametrization: Using non-~collections.abc.Collection iterables (like generators) for argvalues in @pytest.mark.parametrize and metafunc.parametrize is deprecated. This prevents issues where iterables are exhausted after the first use, leading to skipped tests.
  • Configuration & APIs: The private config.inicfg attribute is deprecated in favor of config.getini(). Passing baseid or nodeid strings to fixture registration APIs is deprecated; use the node parameter instead.
  • CLI & Hooks: The --pastebin option is deprecated, now available as an external plugin (pytest-pastebin). pytest.console_main is deprecated; use pytest.main for programmatic execution. The method of configuring hooks using markers, deprecated since pytest 7.2, is also scheduled for removal.

New Features:

  • Warning Control: A significant addition for QA teams is the --max-warnings command-line option and max_warnings configuration option. This allows failing a test run if the number of warnings exceeds a specified threshold, promoting cleaner test suites.
  • Reporting: The --report-chars long CLI option has been added.
  • Fixture Registration: For advanced plugin development, pytest.register_fixture() offers an imperative interface to register fixtures, complementing the declarative @pytest.fixture decorator.
  • Assertion Details: The assertion_text_diff_style configuration option provides more control over assertion failure output.

Impact for QA Teams

QA teams should review their existing test suites for the deprecated patterns, especially concerning fixture usage and parametrization, to prepare for pytest 10. The new --max-warnings option offers a valuable tool for enforcing warning limits, improving test reliability and maintainability. Understanding these changes is crucial for efficient pytest-advanced-techniques and maintaining stable test automation.

FAQ

  • Q: What is the most critical change for existing test suites? A: The potential double execution of autouse fixtures with --doctest-modules requires immediate attention, possibly by moving fixture definitions to conftest.py.
  • Q: How does --max-warnings benefit QA? A: It allows teams to set a warning tolerance, automatically failing builds if too many warnings occur, thus preventing silent issues from accumulating.
  • Q: Do I need to refactor my parametrized tests? A: If you use generators or other non-Collection iterables for argvalues in parametrize, you should refactor them to use lists or tuples to avoid deprecation warnings and potential test skips.