Skip to content

Upgrading pytest 8 to 9

Breaking8.4.2 → 9.2.0Breaking9Security1Platform1Deprecated15New29Changed38Fixed106Other36

BreakingUpgrade verdict

9 breaking changes and a platform requirement change and a security fix.

  • 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.
Top 5 of 26 that need code or config changes

Python requirement changed in 9.0.0: >=3.9 → >=3.10.

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.
-c
Plugin 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.mainpytest11
With --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-packages
Security1
Fixes use of an insecure temporary directory (CVE-2025-71176).
Medium · CVSS 6.8
Platform1
Adds official Python 3.15 support.
Deprecated15
All higher-scoped fixtures (module, package, session) defined as instance methods are now deprecated.
modulepackagesession
Passing 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.
@classmethod
Using 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.CallSpec2CallSpec
The yield_fixture decorator is scheduled for removal in pytest 10 or 11.
yield_fixture
Passing 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.getfixturevalue
The private config.inicfg attribute is deprecated; use config.getini() instead.
config.inicfgconfig.getini()pytest.Config.getini
Passing baseid to FixtureDef or nodeid strings to fixture registration APIs is deprecated; use the node parameter instead.
baseidpytest.FixtureDefnodeidnode
Configuring 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-pastebin
The private FixtureDef.has_location attribute is deprecated and will be removed in pytest 10.
FixtureDef.has_location
pytest.console_main is deprecated and will be removed in pytest 10; use pytest.main instead.
pytest.console_mainpytest.main
Marks yield_fixture as deprecated to type checkers via the deprecated decorator; it was already deprecated in pytest 6.2.
yield_fixture

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