diff options
-rw-r--r-- | CHANGES.rst | 9 | ||||
-rw-r--r-- | coverage/tomlconfig.py | 2 | ||||
-rw-r--r-- | tests/test_config.py | 13 |
3 files changed, 23 insertions, 1 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index ae3428cd..54bbe789 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,9 +20,18 @@ development at the same time, such as 4.5.x and 5.0. Unreleased ---------- +- Fix: if Python doesn't provide tomllib, then TOML configuration files can + only be read if coverage.py is installed with the ``[toml]`` extra. + Coverage.py will raise an error if toml support is not installed when it sees + your settings are in a .toml file. But it didn't understand that + ``[tools.coverage]`` was a valid section header, so the error wasn't + reported, and settings were silently ignored. This is now fixed, closing + `issue 1516`_. + - Fix: adjusted how decorators are traced on PyPy 7.3.10, fixing `issue 1515`_. .. _issue 1515: https://github.com/nedbat/coveragepy/issues/1515 +.. _issue 1516: https://github.com/nedbat/coveragepy/issues/1516 .. _changes_7-0-1: diff --git a/coverage/tomlconfig.py b/coverage/tomlconfig.py index a7d39042..a25b3e35 100644 --- a/coverage/tomlconfig.py +++ b/coverage/tomlconfig.py @@ -52,7 +52,7 @@ class TomlConfigParser: raise TomlDecodeError(str(err)) from err return [filename] else: - has_toml = re.search(r"^\[tool\.coverage\.", toml_text, flags=re.MULTILINE) + has_toml = re.search(r"^\[tool\.coverage(\.|])", toml_text, flags=re.MULTILINE) if self.our_file or has_toml: # Looks like they meant to read TOML, but we can't read it. msg = "Can't read {!r} without TOML support. Install with [toml] extra" diff --git a/tests/test_config.py b/tests/test_config.py index ccc4305f..d88a1a4f 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -739,6 +739,19 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest): with pytest.raises(ConfigError, match=msg): coverage.Coverage() + @pytest.mark.skipif(sys.version_info >= (3, 11), reason="Python 3.11 has toml in stdlib") + def test_no_toml_installed_pyproject_toml_shorter_syntax(self): + # Can't have coverage config in pyproject.toml without toml installed. + self.make_file("pyproject.toml", """\ + # A toml file! + [tool.coverage] + run.parallel = true + """) + with without_module(coverage.tomlconfig, 'tomllib'): + msg = "Can't read 'pyproject.toml' without TOML support" + with pytest.raises(ConfigError, match=msg): + coverage.Coverage() + def test_no_toml_installed_pyproject_no_coverage(self): # It's ok to have non-coverage pyproject.toml without toml installed. self.make_file("pyproject.toml", """\ |