Upgrading pytest 8 to 9
Breaking8.4.2 → 9.2.0Breaking9Security1Platform1Deprecated15New29Changed38Fixed106Other36
SecurityMedium · CVSS 6.8Fixes use of an insecure temporary directory (CVE-2025-71176).GHSA-6w46-j5rx-g56g · CVE-2025-71176 ↗
BreakingUpgrade verdict
9 breaking changes and a platform requirement change and a security fix.
In plain terms
- When parametrizing tests, you must now name the indirect, ids and scope options instead of passing them by position.
- If you point pytest at a config file that is missing, is a folder, or is in a format it cannot read, it now stops with a clear usage error instead of ignoring it or crashing.
- If a plugin cannot be loaded, pytest now tells you clearly whether the plugin was missing or crashed while loading, and exits with a meaningful code.
- If you use --doctest-modules and define certain autouse fixtures directly inside test modules, those fixtures might now run twice.
Must act Top 5 of 26 that need code or config changes
Python requirement changed in 9.0.0: >=3.9 → >=3.10.
What you must change
Breaking9
The
indirect, ids and scope arguments of Metafunc.parametrize() and @pytest.mark.parametrize are now keyword-only.Metafunc.parametrize()pytest.mark.parametrizeindirectidsscope-c now raises a usage error for a path that does not exist, is a directory, or has an unsupported format.-cPlugin import failures at startup are now reported and classified with distinct exit codes instead of a raw traceback and exit code 1.
-ppytest_pluginsPYTEST_PLUGINSpytest.ExitCodepytest.mainpytest11With --doctest-modules, autouse fixtures with module, package or session scope defined inline in test modules may now execute twice.
--doctest-modulespytest.ModuleDoctestModule\: Fixed a bug where an invocation such as pytest a/ a/b would cause only tests from a/b to run, and not other tests under a/.
\: Support for Python 3.9 is dropped following its end of life.
\: Previously, pytest would assume it was running in a CI/CD environment if either of the environment variables \$CI or \$BUILD_NUMBER was defined; now, CI mode is only activated if at least one of…
\: PytestRemovedIn9Warning deprecation warnings are now errors by default.
PytestRemovedIn9Warningdeprecationspytest.ini\: monkeypatch.syspath_prepend() now issues a deprecation warning when the prepended path contains legacy namespace packages (those using pkg_resources.declare_namespace()).
pkg_resources.declare_namespace()monkeypatch-fixup-namespace-packagesSecurity1
Fixes use of an insecure temporary directory (CVE-2025-71176).
Medium · CVSS 6.8Platform1
Adds official Python 3.15 support.
Deprecations to plan for
Deprecated15
All higher-scoped fixtures (module, package, session) defined as instance methods are now deprecated.
modulepackagesessionPassing a non-string value to a string-typed ini option now emits
pytest.PytestRemovedIn10Warning and will raise TypeError in pytest 10.pytest.PytestRemovedIn10Warning[tool.pytest.ini_options]Adds a deprecation warning for class-scoped fixtures defined as instance methods without @classmethod.
@classmethodUsing non-Collection iterables such as generators or iterators for argvalues in parametrize is now deprecated.
argvalues@pytest.mark.parametrizemetafunc.parametrizepytest.Metafunc.parametrizepytest.main()The private
_pytest.python.CallSpec2 name is renamed to CallSpec, with the old alias kept until pytest 10 or 11._pytest.python.CallSpec2CallSpecThe
yield_fixture decorator is scheduled for removal in pytest 10 or 11.yield_fixturePassing
bytes to TerminalReporter.write_line() is deprecated; pass a str instead.TerminalReporter.write_line()Calling request.getfixturevalue() during teardown to request a not-already-requested fixture is deprecated and will error in pytest 10.
request.getfixturevalue()pytest.FixtureRequest.getfixturevalueThe private config.inicfg attribute is deprecated; use config.getini() instead.
config.inicfgconfig.getini()pytest.Config.getiniPassing baseid to FixtureDef or nodeid strings to fixture registration APIs is deprecated; use the node parameter instead.
baseidpytest.FixtureDefnodeidnodeConfiguring hooks using markers, deprecated since pytest 7.2, is scheduled for removal in pytest 10.
The --pastebin option is deprecated; the same functionality is available in the external pytest-pastebin plugin.
--pastebinpytest-pastebinThe private FixtureDef.has_location attribute is deprecated and will be removed in pytest 10.
FixtureDef.has_locationpytest.console_main is deprecated and will be removed in pytest 10; use pytest.main instead.
pytest.console_mainpytest.mainMarks yield_fixture as deprecated to type checkers via the deprecated decorator; it was already deprecated in pytest 6.2.
yield_fixtureAPI changes
Generated by DepDelta from published Python source. Not mixed with prose notes.
- removed:
export PytestRemovedIn9Warning - added:
export Approx - added:
export ParameterSet - added:
export PytestApproxDecimalToleranceWarning - added:
export PytestRemovedIn10Warning - added:
export ScopeName - added:
export SubtestReport - added:
export Subtests - added:
export register_fixture