Pytest 9.1.0 Update: Key Changes for QA Automation
TL;DR
--doctest-modulesusers: autouse fixtures might run twice; consider moving them toconftest.py.- Several key deprecations, including
request.getfixturevalue()during teardown and non-Collection iterables inparametrize. - New
--max-warningsoption 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.Collectioniterables (like generators) forargvaluesin@pytest.mark.parametrizeandmetafunc.parametrizeis deprecated. This prevents issues where iterables are exhausted after the first use, leading to skipped tests. - Configuration & APIs: The private
config.inicfgattribute is deprecated in favor ofconfig.getini(). Passingbaseidornodeidstrings to fixture registration APIs is deprecated; use thenodeparameter instead. - CLI & Hooks: The
--pastebinoption is deprecated, now available as an external plugin (pytest-pastebin).pytest.console_mainis deprecated; usepytest.mainfor 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-warningscommand-line option andmax_warningsconfiguration option. This allows failing a test run if the number of warnings exceeds a specified threshold, promoting cleaner test suites. - Reporting: The
--report-charslong 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.fixturedecorator. - Assertion Details: The
assertion_text_diff_styleconfiguration 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-modulesrequires immediate attention, possibly by moving fixture definitions toconftest.py. - Q: How does
--max-warningsbenefit 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
argvaluesinparametrize, you should refactor them to use lists or tuples to avoid deprecation warnings and potential test skips.
