8.4.0
Breaking Changes📦 pytestView on GitHub →
⚠4 breaking✨ 10 features⚡ 1 deprecations🔧 11 symbols
Summary
pytest 8.4.0 introduces significant breaking changes—removing Python 3.8 support, enforcing stricter test return values, and disallowing yield tests—while adding powerful new features like RaisesGroup, enhanced xfail handling, and configurable output options.
⚠️ Breaking Changes
- Async tests now fail instead of warning+skipping when no suitable async plugin is installed; install an appropriate plugin or disable async tests to avoid failures.
- Test functions that return a value other than None now cause a failure; ensure test functions return None or remove return statements.
- Support for Python 3.8 has been removed; upgrade the interpreter to Python 3.9 or newer.
- Test functions containing a yield now raise an explicit error; rewrite yield‑based tests using standard parametrization or other mechanisms.
Migration Steps
- Install an async‑test plugin (e.g., pytest-asyncio) or remove async tests to avoid failures caused by the new async test handling.
- Remove any return statements from test functions or ensure they return None to comply with the new non‑None return failure rule.
- Rewrite or delete tests that use yield statements; they now raise an explicit error.
- If you rely on async fixtures without a pytest_fixture_setup hook, add the appropriate hook or adjust fixture definitions to silence the DeprecationWarning.
- Consider setting collect_imported_tests = false in your pytest.ini if you want to avoid collecting imported test classes/functions.
- Update any custom truncation logic to use the new truncation_limit_lines or truncation_limit_chars settings if needed.
- If you used the PYTEST_DISABLE_PLUGIN_AUTOLOAD environment variable, you can now replace it with the --disable-plugin-autoload flag or the corresponding addopts entry.
✨ New Features
- Added pytest.RaisesGroup class for asserting ExceptionGroup objects and pytest.RaisesExc class as the underlying logic for pytest.raises.
- Introduced capteesys fixture to capture output and pass it to the next handler set by --capture.
- pytest.mark.xfail now accepts pytest.RaisesGroup (and pytest.RaisesExc) for the raises parameter, enabling expectation of exception groups.
- New --force-short-summary command‑line option to force condensed summary output regardless of verbosity.
- New collect_imported_tests configuration option (default true) can be set to false to prevent collecting imported test classes/functions.
- Added truncation_limit_lines and truncation_limit_chars configuration values to control snippet truncation thresholds.
- console_output_style now supports the 'times' option to display execution time per test.
- pytest.raises now warns when match is an empty string, prints a helpful diff for regex mismatches, and supports a check callable for custom validation.
- hidden‑param can now be used in the id of pytest.param or in ids of Metafunc.parametrize to hide parameter sets from test names.
- New --disable-plugin-autoload flag provides an alternative to the PYTEST_DISABLE_PLUGIN_AUTOLOAD environment variable and can be set via addopts.
đź”§ Affected Symbols
pytest.RaisesGrouppytest.RaisesExccapteesyspytest.mark.xfailcollect_imported_teststruncation_limit_linestruncation_limit_charsconsole_output_stylepytest.raiseshidden-param--disable-plugin-autoload⚡ Deprecations
- Requesting an asynchronous fixture without a pytest_fixture_setup hook now triggers a DeprecationWarning; add a proper fixture setup hook or adjust async fixture usage.