From 02a338f7dfe9d30334f273df6aba7e7d4f7aa1be Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Tue, 8 Mar 2022 01:08:52 -0800 Subject: [PATCH 1/3] Use tomllib on Python 3.11 --- setup.cfg | 2 +- src/_pytest/config/findpaths.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/setup.cfg b/setup.cfg index fe6ea4095bc..f3ac25ee146 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,7 +46,7 @@ install_requires = packaging pluggy>=0.12,<2.0 py>=1.8.2 - tomli>=1.0.0 + tomli>=1.0.0;python_version<"3.11" atomicwrites>=1.0;sys_platform=="win32" colorama;sys_platform=="win32" importlib-metadata>=0.12;python_version<"3.8" diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py index c082e652d92..ead344baac5 100644 --- a/src/_pytest/config/findpaths.py +++ b/src/_pytest/config/findpaths.py @@ -1,4 +1,5 @@ import os +import sys from pathlib import Path from typing import Dict from typing import Iterable @@ -64,12 +65,15 @@ def load_config_dict_from_file( # '.toml' files are considered if they contain a [tool.pytest.ini_options] table. elif filepath.suffix == ".toml": - import tomli + if sys.version_info >= (3, 11): + import tomllib + else: + import tomli as tomllib toml_text = filepath.read_text(encoding="utf-8") try: - config = tomli.loads(toml_text) - except tomli.TOMLDecodeError as exc: + config = tomllib.loads(toml_text) + except tomllib.TOMLDecodeError as exc: raise UsageError(f"{filepath}: {exc}") from exc result = config.get("tool", {}).get("pytest", {}).get("ini_options", None) From c91f08a2f5405c11f248235c2487f14e25ebaf71 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 8 Mar 2022 09:11:19 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index f3ac25ee146..c4f5bd9d29f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,10 +46,10 @@ install_requires = packaging pluggy>=0.12,<2.0 py>=1.8.2 - tomli>=1.0.0;python_version<"3.11" atomicwrites>=1.0;sys_platform=="win32" colorama;sys_platform=="win32" importlib-metadata>=0.12;python_version<"3.8" + tomli>=1.0.0;python_version<"3.11" python_requires = >=3.7 package_dir = =src From d4ad9f0b015407619a7654e15b43600a45a27b59 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Tue, 8 Mar 2022 01:12:34 -0800 Subject: [PATCH 3/3] changelog --- changelog/9741.improvement.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/9741.improvement.rst diff --git a/changelog/9741.improvement.rst b/changelog/9741.improvement.rst new file mode 100644 index 00000000000..1f9ab3eadf2 --- /dev/null +++ b/changelog/9741.improvement.rst @@ -0,0 +1,3 @@ +On Python 3.11, use the standard library's :mod:`tomllib` to parse TOML. + +:mod:`tomli`` is no longer a dependency on Python 3.11.