Skip to content

Conversation

@OlenaYefymenko
Copy link
Contributor

This patch provides a new configuration — .coveragerc.toml . Considering that many projects have switched to toml configurations, this change offers a more flexible approach to manage coverage settings.

Resolves #1643

Comment on lines 67 to 80
@pytest.mark.parametrize("filename", ["pyproject.toml", ".coveragerc.toml"])
def test_toml_config_file(self, filename) -> None:
# A pyproject.toml and coveragerc.toml will be read into the configuration.
self.make_file(filename, """\
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the parameterization implemented appropriately, similar to pyproject.toml?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

@OlenaYefymenko
Copy link
Contributor Author

@nedbat,
I've opened PR with the improvements, but I have a few doubts about my implementation. I've added comments in the code. I'd really appreciate your feedback on whether this approach works well.
Thank you!

@nedbat nedbat changed the title 🌐 Support .coveragerc.toml for configuration Support .coveragerc.toml for configuration Apr 16, 2025
Copy link
Member

@nedbat nedbat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One change needed.

Comment on lines 67 to 80
@pytest.mark.parametrize("filename", ["pyproject.toml", ".coveragerc.toml"])
def test_toml_config_file(self, filename) -> None:
# A pyproject.toml and coveragerc.toml will be read into the configuration.
self.make_file(filename, """\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

""")
with mock.patch.object(coverage.tomlconfig, "has_tomllib", False):
msg = "Can't read 'pyproject.toml' without TOML support"
msg = "Can't read '{filename}' without TOML support"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like tests are failing because this needs to be an f-string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I will fix this error in the next commits. I run tox with version 3.12 locally, and I didn't see this error.

@nedbat
Copy link
Member

nedbat commented Apr 16, 2025

Thanks for doing this. There are some other changes needed. Let me know which you want to do, and which I should do:

  • Update the documentation
  • Add an entry to CHANGES.rst
  • Add your name to CONTRIBUTORS.txt

@OlenaYefymenko
Copy link
Contributor Author

OlenaYefymenko commented Apr 17, 2025

Thanks for doing this. There are some other changes needed. Let me know which you want to do, and which I should do:

  • Update the documentation
  • Add an entry to CHANGES.rst
  • Add your name to CONTRIBUTORS.txt

Yes, I will add the changes

@OlenaYefymenko OlenaYefymenko marked this pull request as draft May 7, 2025 21:32
@OlenaYefymenko OlenaYefymenko force-pushed the support-configuration-coverage-toml branch from 4018790 to 673b0c0 Compare June 15, 2025 23:16
@OlenaYefymenko OlenaYefymenko force-pushed the support-configuration-coverage-toml branch from 673b0c0 to c584e0d Compare July 20, 2025 13:52
Copy link
Contributor

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz revert all the formatting changes. I marked some, find the rest.

@OlenaYefymenko OlenaYefymenko force-pushed the support-configuration-coverage-toml branch from 6bee75f to 7565729 Compare August 18, 2025 22:17
@OlenaYefymenko OlenaYefymenko force-pushed the support-configuration-coverage-toml branch from 7565729 to 2558209 Compare August 31, 2025 22:19
CHANGES.rst Outdated
.. _pull 1952: https://github.com/nedbat/coveragepy/pull/1952


.. start-releases
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid conflict resolution?

doc/config.rst Outdated
[html]
directory = coverage_html_report
""",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray edit?

"""\
@pytest.mark.parametrize("filename", ["pyproject.toml", ".coveragerc.toml"])
def test_toml_config_file(self, filename: str) -> None:
# A pyproject.toml and coveragerc.toml will be read into the configuration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# A pyproject.toml and coveragerc.toml will be read into the configuration.
# A pyproject.toml and .coveragerc.toml will be read into the configuration.

def test_toml_parse_errors(self, bad_config: str, msg: str) -> None:
@pytest.mark.parametrize("filename", ["pyproject.toml", ".coveragerc.toml"])
@pytest.mark.parametrize("bad_config, msg", [
("[tool.coverage.run]\ntimid = \"maybe?\"\n", r"maybe[?]"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of reformatting?

assert cov.config.xml_output == "/Users/me/somewhere/xml.out"
assert cov.config.exclude_list == ["~/data.file", "~joe/html_dir"]
assert cov.config.paths == {"mapping": ["/Users/me/src", "/Users/joe/source"]}
assert cov.config.paths == {'mapping': ['/Users/me/src', '/Users/joe/source']}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

self.make_file(
"pyproject.toml",
"""\
self.make_file("pyproject.toml", """\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@OlenaYefymenko
Copy link
Contributor Author

I'm in progress - some tests have failed, I'm going to fix them

@OlenaYefymenko
Copy link
Contributor Author

@OlenaYefymenko Heads up that a rebase is now required because there are conflicts.

@ofek yep. I will do the rebase, yesterday I had some issues with it for some reason.
In the next commit I will also add the test, and that will be the final update. Thanks for pointing it out.

@OlenaYefymenko OlenaYefymenko force-pushed the support-configuration-coverage-toml branch from 1f2edbb to f746384 Compare December 3, 2025 22:42
OlenaYefymenko and others added 17 commits December 7, 2025 00:24
This adds .coveragerc.toml to the list of configuration files that
coverage.py will automatically search for, with higher priority
than pyproject.toml but lower than .coveragerc.
Converts existing pyproject.toml tests to be parametrized to also
test .coveragerc.toml functionality, ensuring both TOML config
formats work identically.
This test ensures that when both .coveragerc.toml and pyproject.toml
are present, .coveragerc.toml takes precedence as intended.
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
@OlenaYefymenko OlenaYefymenko force-pushed the support-configuration-coverage-toml branch from 13a7188 to 9b6c00c Compare December 6, 2025 22:28
@OlenaYefymenko
Copy link
Contributor Author

@nedbat please take a look at the PR to see if it's ready to be merged

Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
@nedbat nedbat merged commit 21e726f into coveragepy:main Dec 7, 2025
44 checks passed
@nedbat
Copy link
Member

nedbat commented Dec 7, 2025

Thanks for persisting with this! <3

@nedbat
Copy link
Member

nedbat commented Dec 7, 2025

This landed in commit 21e726f

@nedbat
Copy link
Member

nedbat commented Dec 8, 2025

This is now released as part of coverage 7.13.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] Tool-specific toml config

7 participants