Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ log_cli_level = "INFO"
minversion = "7"

[tool.coverage.run]
relative_files = true
source = [ "src" ]
omit = [ "*/pytest-of-*/*", "*/_temp/*" ]

Expand Down
26 changes: 26 additions & 0 deletions src/usethis/_tool/impl/coverage_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,32 @@ def _get_source():
),
},
),
ConfigItem(
# https://github.com/usethis-python/usethis-python/issues/930
# This config helps ensure reports generated in CI environments
# have consistent paths between jobs, by forcing them to be relative
description="Relative Files Configuration",
root={
Path(".coveragerc"): ConfigEntry(
keys=["run", "relative_files"], get_value=lambda: "true"
),
Path(".coveragerc.toml"): ConfigEntry(
keys=["run", "relative_files"], get_value=lambda: True
),
Path("setup.cfg"): ConfigEntry(
keys=["coverage:run", "relative_files"],
get_value=lambda: "true",
),
Path("tox.ini"): ConfigEntry(
keys=["coverage:run", "relative_files"],
get_value=lambda: "true",
),
Path("pyproject.toml"): ConfigEntry(
keys=["tool", "coverage", "run", "relative_files"],
get_value=lambda: True,
),
},
),
ConfigItem(
description="Report Configuration",
root={
Expand Down
2 changes: 2 additions & 0 deletions tests/usethis/_core/test_core_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ def test_coverage_rc_file(self, uv_init_dir: Path):
[run]
source =
src
relative_files = true

[report]
exclude_also =
Expand Down Expand Up @@ -464,6 +465,7 @@ def test_tox_ini_file(self, uv_init_dir: Path):
[coverage:run]
source =
src
relative_files = true

[coverage:report]
exclude_also =
Expand Down
16 changes: 16 additions & 0 deletions tests/usethis/_tool/impl/test_coverage_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,19 @@ def test_coveragerc_preferred_over_coveragerc_toml(self, tmp_path: Path):
assert (tmp_path / ".coveragerc.toml").read_text() == (
'[run]\nsource = ["existing"]\n'
)

def test_relative_files_set_to_true(self, tmp_path: Path):
# Arrange
(tmp_path / "pyproject.toml").write_text("""\
[project]
name = "example"
version = "0.1.0"
""")

# Act
with change_cwd(tmp_path), files_manager():
CoveragePyTool().add_configs()

# Assert
content = (tmp_path / "pyproject.toml").read_text()
assert "relative_files = true" in content