Skip to content

Commit ce5e02f

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

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

tests/test_config.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -799,39 +799,35 @@ def test_no_toml_installed_explicit_toml(self) -> None:
799799
coverage.Coverage(config_file="cov.toml")
800800

801801
@pytest.mark.skipif(env.PYVERSION >= (3, 11), reason="Python 3.11 has toml in stdlib")
802-
@pytest.mark.parametrize("filename", ["pyproject.toml", ".coveragerc.toml"])
803-
def test_no_toml_installed_pyproject_toml(self, filename) -> None:
804-
# Can't have coverage config in pyproject.toml and .coveragerc.toml without toml installed.
805-
self.make_file(filename, """\
802+
def test_no_toml_installed_pyproject_toml(self) -> None:
803+
# Can't have coverage config in pyproject.toml without toml installed.
804+
self.make_file("pyproject.toml", """\
806805
# A toml file!
807806
[tool.coverage.run]
808807
xyzzy = 17
809808
""")
810809
with mock.patch.object(coverage.tomlconfig, "has_tomllib", False):
811-
msg = f"Can't read '{filename}' without TOML support"
810+
msg = "Can't read 'pyproject.toml' without TOML support"
812811
with pytest.raises(ConfigError, match=msg):
813812
coverage.Coverage()
814813

815814
@pytest.mark.skipif(env.PYVERSION >= (3, 11), reason="Python 3.11 has toml in stdlib")
816-
@pytest.mark.parametrize("filename", ["pyproject.toml", ".coveragerc.toml"])
817-
def test_no_toml_installed_pyproject_toml_shorter_syntax(self, filename) -> None:
815+
def test_no_toml_installed_pyproject_toml_shorter_syntax(self) -> None:
818816
# Can't have coverage config in pyproject.toml without toml installed.
819-
self.make_file(filename, """\
817+
self.make_file("pyproject.toml", """\
820818
# A toml file!
821819
[tool.coverage]
822820
run.parallel = true
823821
""")
824822
with mock.patch.object(coverage.tomlconfig, "has_tomllib", False):
825-
msg = f"Can't read '{filename}' without TOML support"
823+
msg = "Can't read 'pyproject.toml' without TOML support"
826824
with pytest.raises(ConfigError, match=msg):
827825
coverage.Coverage()
828826

829-
830827
@pytest.mark.skipif(env.PYVERSION >= (3, 11), reason="Python 3.11 has toml in stdlib")
831-
@pytest.mark.parametrize("filename", ["pyproject.toml", ".coveragerc.toml"])
832-
def test_no_toml_installed_pyproject_no_coverage(self, filename) -> None:
828+
def test_no_toml_installed_pyproject_no_coverage(self) -> None:
833829
# It's ok to have non-coverage pyproject.toml without toml installed.
834-
self.make_file(filename, """\
830+
self.make_file("pyproject.toml", """\
835831
# A toml file!
836832
[tool.something]
837833
xyzzy = 17
@@ -878,3 +874,27 @@ def test_coveragerc_toml_priority(self) -> None:
878874
assert cov.config.timid is True
879875
assert cov.config.data_file == ".toml-data.dat"
880876
assert cov.config.branch is True
877+
878+
879+
@pytest.mark.skipif(env.PYVERSION >= (3, 11), reason="Python 3.11 has toml in stdlib")
880+
def test_toml_file_exists_but_no_toml_support(self) -> None:
881+
"""Test behavior when .coveragerc.toml exists but TOML support is missing."""
882+
self.make_file(".coveragerc.toml", """\
883+
[tool.coverage.run]
884+
timid = true
885+
data_file = ".toml-data.dat"
886+
""")
887+
888+
with mock.patch.object(coverage.tomlconfig, "has_tomllib", False):
889+
msg = "Can't read '.coveragerc.toml' without TOML support"
890+
with pytest.raises(ConfigError, match=msg):
891+
coverage.Coverage(config_file=".coveragerc.toml")
892+
self.make_file(".coveragerc", """\
893+
[run]
894+
timid = false
895+
data_file = .ini-data.dat
896+
""")
897+
898+
cov = coverage.Coverage()
899+
assert not cov.config.timid
900+
assert cov.config.data_file == ".ini-data.dat"

0 commit comments

Comments
 (0)