Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tomllib on Python 3.11 #9741

Merged
merged 4 commits into from Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions 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.
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -46,10 +46,10 @@ install_requires =
packaging
pluggy>=0.12,<2.0
py>=1.8.2
tomli>=1.0.0
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
Expand Down
10 changes: 7 additions & 3 deletions 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
Expand Down Expand Up @@ -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)
Expand Down