1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
cherry picked from https://github.com/jrnl-org/jrnl/pull/2028
From: "Benjamin A. Beasley" <code@musicinmybrain.net>
Date: Fri, 15 Aug 2025 10:33:31 -0400
Subject: [PATCH] For Python 3.11, use `tomllib` for tests
Avoid a test dependency on the PyPI `toml` package.
--- a/tests/lib/fixtures.py
+++ b/tests/lib/fixtures.py
@@ -2,6 +2,7 @@
# License: https://www.gnu.org/licenses/gpl-3.0.html
import os
+import sys
import tempfile
from collections import defaultdict
from collections.abc import Iterable
@@ -9,7 +10,6 @@
from unittest.mock import Mock
from unittest.mock import patch
-import toml
from keyring import backend
from keyring import errors
from pytest import fixture
@@ -203,8 +203,16 @@ def working_dir(request):
@fixture
def toml_version(working_dir):
- pyproject = os.path.join(working_dir, "..", "pyproject.toml")
- pyproject_contents = toml.load(pyproject)
+ pyproject_path = os.path.join(working_dir, "..", "pyproject.toml")
+ if sys.version_info >= (3, 11):
+ import tomllib
+
+ with open(pyproject_path, "rb") as pyproject:
+ pyproject_contents = tomllib.load(pyproject)
+ else:
+ import toml
+
+ pyproject_contents = toml.load(pyproject_path)
return pyproject_contents["tool"]["poetry"]["version"]
|