Skip to content

Commit

Permalink
fix: [tools.coverage] is valid for settings in a toml file. #1516
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Dec 28, 2022
1 parent 012a687 commit 3823cc6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGES.rst
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion coverage/tomlconfig.py
Expand Up @@ -52,7 +52,7 @@ def read(self, filenames):
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"
Expand Down
13 changes: 13 additions & 0 deletions tests/test_config.py
Expand Up @@ -739,6 +739,19 @@ def test_no_toml_installed_pyproject_toml(self):
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", """\
Expand Down

0 comments on commit 3823cc6

Please sign in to comment.