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