Skip to content

Remove support for Python 3.10 - #15163

Open
Pierre-Sassoulas wants to merge 8 commits into
pytest-dev:mainfrom
Pierre-Sassoulas:drop-python-3.10
Open

Pierre-Sassoulas wants to merge 8 commits into
pytest-dev:mainfrom
Pierre-Sassoulas:drop-python-3.10

Conversation

@Pierre-Sassoulas

Copy link
Copy Markdown
Member

Python 3.10 reached end of life in October 2026. Drop the exceptiongroup, tomli and asynctest dependencies and the version-conditional code paths that existed only for it.

@Pierre-Sassoulas Pierre-Sassoulas added type: refactoring internal improvements to the code dependencies pull requests that update a dependency file labels Oct 11, 2026
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 11, 2026

Copy link
Copy Markdown
Member

🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.

The _find_lineno workaround in src/_pytest/doctest.py loses its coverage with this change. It now applies to 3.11 < 3.11.9 and 3.12 < 3.12.3. Until now, 3.10 was the only CI interpreter that went through it, and setup-python always installs the latest patch release.

We still support those interpreters (Debian 12 ships 3.11.2), so either:

  • add a floor job pinned to an old 3.11 patch release that only runs the affected tests (testing/test_doctest.py, set through _PYTEST_FILES the same way the twisted envs do it), or
  • mark the branch # pragma: no cover and accept that it's untested.

The changelog file also needs the PR number: changelog/15163.breaking.rst.


Generated by Claude Code

@Pierre-Sassoulas
Pierre-Sassoulas marked this pull request as ready for review October 11, 2026 12:53
@Pierre-Sassoulas

Copy link
Copy Markdown
Member Author

Thank you for the review @RonnyPfannschmidt , fixed in b10422d

@bluetech

Copy link
Copy Markdown
Member

I'm preparing to release pytest 9.2 (I think I'll open an issue for it now). I think we might as well leave 3.10 support for this release and drop it in 10.0. (To be clear, our policy allows dropping old Python support in minor releases, just thinking since we've done the work for this release, might as well keep it). Let me know if you think differently.

Comment thread src/_pytest/_py/error.py Outdated
@@ -11,7 +11,7 @@


if TYPE_CHECKING:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we can drop the TYPE_CHECKING now.

Comment thread pyproject.toml Outdated
[tool.black]
# See https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#t-target-version
target-version = [ "py310", "py311", "py312", "py313" ]
target-version = [ "py311", "py312", "py313" ]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, seems like this is missing py314. Or, given that the link says black supports deriving this info from project.requires-python, maybe can just drop it?

Comment thread pyproject.toml Outdated

[tool.ruff]
target-version = "py310"
target-version = "py311"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW2, Ruff also says it considers project.requires-python for this https://docs.astral.sh/ruff/settings/#target-version, so should be possible to just drop this line as well.

Comment thread testing/python/approx.py
from datetime import timezone

tz = timezone.utc
tz = UTC

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I prefer datetime.UTC when datetime import is already available. A bit clearer.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't do it because there's a from datetime import datetime so it'd require a prior refactor.

Comment thread src/_pytest/subtests.py Outdated
@@ -41,7 +41,7 @@


if TYPE_CHECKING:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can drop the TYPE_CHECKING

Comment thread src/_pytest/stepwise.py Outdated
@@ -16,7 +16,7 @@


if TYPE_CHECKING:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can drop the TYPE_CHECKING

@bluetech

Copy link
Copy Markdown
Member

BTW, I remembered this Python 3.11 changelog

warnings.catch_warnings() now accepts arguments for warnings.simplefilter(), providing a more concise way to locally ignore warnings or convert them to errors. (Contributed by Zac Hatfield-Dodds in bpo-47074.)

I think we have a lot of cases in of the old pattern (with catch_warnings(): simplefilter()) in the docs and tests which we could now combine into one line. Thanks @Zac-HD :)

@Pierre-Sassoulas Pierre-Sassoulas added this to the 10.0 milestone Oct 18, 2026
Pierre-Sassoulas and others added 7 commits October 18, 2026 22:31
Python 3.10 reached end of life in October 2026. Drop the exceptiongroup,
tomli and asynctest dependencies and the version-conditional code paths
that existed only for it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
importlib.resources.abc exists since Python 3.11, so the version check
was only needed for 3.10. Also refresh a docstring that still mentioned
Python 3.10.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
With Python 3.10 gone, the latest patch releases that setup-python
installs never hit the workaround for python/cpython#61648, which was
fixed in 3.11.9 and 3.12.3. Add a `floor` tox factor that runs only
testing/test_doctest.py, and a CI job using it on 3.11.2, the version
Debian 12 ships.

Also name the changelog fragment after the pull request.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Both are available in typing since Python 3.11, so the TYPE_CHECKING
blocks that only existed for them are no longer needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both tools derive their target version from ``project.requires-python``
when it is not configured, so the explicit lists only had to be kept in
sync by hand. Black is only run through blacken-docs, which does not read
``[tool.black]`` at all, so the section had no effect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Matches the local imports of the other datetime tests in the class.
``datetime.UTC`` cannot be used there because the local
``from datetime import datetime`` shadows the module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since Python 3.11, ``warnings.catch_warnings()`` accepts the arguments of
``warnings.simplefilter()``, so the ``with catch_warnings():`` followed by
``simplefilter()`` pattern can be written in one line, in the docs as well
as in the code and tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Pierre-Sassoulas

Copy link
Copy Markdown
Member Author

Did the warning refactor in 32422f4

@Pierre-Sassoulas

Copy link
Copy Markdown
Member Author

The coverage fail comes from the catch_warnings(action="error") in testing/test_monkeypatch.py, in test_syspath_prepend_with_namespace_packages. That test is skipped in every CI job: it does pytest.importorskip("pkg_resources"), and pkg_resources isn't installed in any of our environments. Should we remove or should we make it run ?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR dependencies pull requests that update a dependency file type: refactoring internal improvements to the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants