From 0314b50c52658093d79e2d5af5358e384f26d507 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Mon, 31 Oct 2022 17:49:51 +0200 Subject: [PATCH] Fix 'importlib.abc.TraversableResources' deprecation warning in Python 3.12 (#10452) --- changelog/10452.bugfix.rst | 1 + src/_pytest/assertion/rewrite.py | 7 ++++++- tox.ini | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelog/10452.bugfix.rst diff --git a/changelog/10452.bugfix.rst b/changelog/10452.bugfix.rst new file mode 100644 index 000000000..d8f7dded4 --- /dev/null +++ b/changelog/10452.bugfix.rst @@ -0,0 +1 @@ +Fix 'importlib.abc.TraversableResources' deprecation warning in Python 3.12. diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index 63f9dd8f2..cb64a33c0 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -275,7 +275,12 @@ class AssertionRewritingHook(importlib.abc.MetaPathFinder, importlib.abc.Loader) if sys.version_info >= (3, 10): - def get_resource_reader(self, name: str) -> importlib.abc.TraversableResources: # type: ignore + if sys.version_info >= (3, 12): + from importlib.resources.abc import TraversableResources + else: + from importlib.abc import TraversableResources + + def get_resource_reader(self, name: str) -> TraversableResources: # type: ignore if sys.version_info < (3, 11): from importlib.readers import FileReader else: diff --git a/tox.ini b/tox.ini index f04242c5c..c80fdfcd1 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,7 @@ envlist = py39 py310 py311 + py312 pypy3 py37-{pexpect,xdist,unittestextras,numpy,pluggymain,pylib} doctesting