Skip to content

Commit c3965d5

Browse files
This patch parametrizes tests for configuration files.
Adds a new test to verify behavior when TOML support is unavailable.
1 parent b41d75b commit c3965d5

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

tests/test_config.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -859,38 +859,35 @@ def test_no_toml_installed_explicit_toml(self) -> None:
859859
coverage.Coverage(config_file="cov.toml")
860860

861861
@pytest.mark.skipif(env.PYVERSION >= (3, 11), reason="Python 3.11 has toml in stdlib")
862-
@pytest.mark.parametrize("filename", ["pyproject.toml", ".coveragerc.toml"])
863-
def test_no_toml_installed_pyproject_toml(self, filename) -> None:
864-
# Can't have coverage config in pyproject.toml and .coveragerc.toml without toml installed.
865-
self.make_file(filename, """\
862+
def test_no_toml_installed_pyproject_toml(self) -> None:
863+
# Can't have coverage config in pyproject.toml without toml installed.
864+
self.make_file("pyproject.toml", """\
866865
# A toml file!
867866
[tool.coverage.run]
868867
xyzzy = 17
869868
""")
870869
with mock.patch.object(coverage.tomlconfig, "has_tomllib", False):
871-
msg = f"Can't read '{filename}' without TOML support"
870+
msg = "Can't read 'pyproject.toml' without TOML support"
872871
with pytest.raises(ConfigError, match=msg):
873872
coverage.Coverage()
874873

875874
@pytest.mark.skipif(env.PYVERSION >= (3, 11), reason="Python 3.11 has toml in stdlib")
876-
@pytest.mark.parametrize("filename", ["pyproject.toml", ".coveragerc.toml"])
877-
def test_no_toml_installed_pyproject_toml_shorter_syntax(self, filename) -> None:
875+
def test_no_toml_installed_pyproject_toml_shorter_syntax(self) -> None:
878876
# Can't have coverage config in pyproject.toml without toml installed.
879-
self.make_file(filename, """\
877+
self.make_file("pyproject.toml", """\
880878
# A toml file!
881879
[tool.coverage]
882880
run.parallel = true
883881
""")
884882
with mock.patch.object(coverage.tomlconfig, "has_tomllib", False):
885-
msg = f"Can't read '{filename}' without TOML support"
883+
msg = "Can't read 'pyproject.toml' without TOML support"
886884
with pytest.raises(ConfigError, match=msg):
887885
coverage.Coverage()
888886

889887
@pytest.mark.skipif(env.PYVERSION >= (3, 11), reason="Python 3.11 has toml in stdlib")
890-
@pytest.mark.parametrize("filename", ["pyproject.toml", ".coveragerc.toml"])
891-
def test_no_toml_installed_pyproject_no_coverage(self, filename) -> None:
888+
def test_no_toml_installed_pyproject_no_coverage(self) -> None:
892889
# It's ok to have non-coverage pyproject.toml without toml installed.
893-
self.make_file(filename, """\
890+
self.make_file("pyproject.toml", """\
894891
# A toml file!
895892
[tool.something]
896893
xyzzy = 17
@@ -937,3 +934,27 @@ def test_coveragerc_toml_priority(self) -> None:
937934
assert cov.config.timid is True
938935
assert cov.config.data_file == ".toml-data.dat"
939936
assert cov.config.branch is True
937+
938+
939+
@pytest.mark.skipif(env.PYVERSION >= (3, 11), reason="Python 3.11 has toml in stdlib")
940+
def test_toml_file_exists_but_no_toml_support(self) -> None:
941+
"""Test behavior when .coveragerc.toml exists but TOML support is missing."""
942+
self.make_file(".coveragerc.toml", """\
943+
[tool.coverage.run]
944+
timid = true
945+
data_file = ".toml-data.dat"
946+
""")
947+
948+
with mock.patch.object(coverage.tomlconfig, "has_tomllib", False):
949+
msg = "Can't read '.coveragerc.toml' without TOML support"
950+
with pytest.raises(ConfigError, match=msg):
951+
coverage.Coverage(config_file=".coveragerc.toml")
952+
self.make_file(".coveragerc", """\
953+
[run]
954+
timid = false
955+
data_file = .ini-data.dat
956+
""")
957+
958+
cov = coverage.Coverage()
959+
assert not cov.config.timid
960+
assert cov.config.data_file == ".ini-data.dat"

0 commit comments

Comments
 (0)