Skip to content

Commit f4ef895

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
tests: support testing toml with tomli or tomllib
Skip the toml related test cases only if neither tomli or tomllib are available. Signed-off-by: John Mulligan <[email protected]>
1 parent 3905ed7 commit f4ef895

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

tests/test_config.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,23 @@ def test_permissions_config_options():
756756
assert "friendship" in opts
757757

758758

759+
def _can_import_toml():
760+
"""Return true if one valid toml module can be imported.
761+
Work around importorskip only supporting one module name.
762+
"""
763+
try:
764+
__import__("tomllib")
765+
return True
766+
except ImportError:
767+
pass
768+
try:
769+
__import__("tomli")
770+
return True
771+
except ImportError:
772+
pass
773+
return False
774+
775+
759776
@pytest.mark.parametrize(
760777
"json_str,ok",
761778
[
@@ -943,9 +960,8 @@ def test_jsonschema_validation(json_str, ok):
943960
),
944961
],
945962
)
963+
@pytest.mark.skipif(not _can_import_toml(), reason="no toml module")
946964
def test_toml_configs_no_validation(toml_str, ok):
947-
pytest.importorskip("tomllib")
948-
949965
cfg = sambacc.config.GlobalConfig()
950966
fh = io.BytesIO(toml_str.encode("utf8"))
951967
if ok:
@@ -1059,8 +1075,8 @@ def test_toml_configs_no_validation(toml_str, ok):
10591075
),
10601076
],
10611077
)
1078+
@pytest.mark.skipif(not _can_import_toml(), reason="no toml module")
10621079
def test_toml_configs_validation(toml_str, ok):
1063-
pytest.importorskip("tomllib")
10641080
jsonschema = pytest.importorskip("jsonschema")
10651081

10661082
cfg = sambacc.config.GlobalConfig()

0 commit comments

Comments
 (0)