Why are we turning off the `cov-report` output gen...
# development
r
Why are we turning off the
cov-report
output generated by
pytest --cov
? I don’t understand what’s the point of then even running
pytest --cov
? https://github.com/pantsbuild/pants/blob/main/src/python/pants/backend/python/goals/pytest_runner.py#L359 I think this is the reason behind this issue
e
Make sure you've read https://github.com/pantsbuild/pants/blob/589c4e635f3dd97cf5b104c6d05bca7bd61aea3c/src/python/pants/backend/python/goals/coverage_py.py#L68 to get the fuller picture of how coverage is handled. Pants does not do it all just by delegating to pytest.
r
So what I was unaware about was the
.coverage
being generated by
pytest-cov
. Otherwise I had the fuller picture. Now what I am confused about is where this is breaking when using the filter option. What I tried was to replace the source roots with what I pass in filter directly and this shows the coverage of files without any tests also.
Copy code
--- a/src/python/pants/backend/python/goals/coverage_py.py
+++ b/src/python/pants/backend/python/goals/coverage_py.py
@@ -411,7 +411,7 @@ async def merge_coverage_data(
                     "coverage": {
                         "run": {
                             "relative_files": True,
-                            "source": [source_root.path for source_root in source_roots],
+                            "source": [path for path in coverage.filter],
                             "branch": branch,
                         }
                     }
e
So ... the obvious thing here is you're using coverage 7 and Pants ships supporting
>=6.5,<6.6
. Given the major version bump alone, but also glancing at the coverage change log (https://coverage.readthedocs.io/en/7.0.5/changes.html), problems should generally be expected. Pants relies on some coverage APIs to interoperate and the major version bump to 7 allows for APIs to be broken per semver. So 2 questions: 1. What forces you to use coverage 7? 2. Have you tried using Pants default coverage / does it lead to this same issue?
r
1. I actually thought it was issue with the coverage/pytest-cov. So I wanted to check if using newer versions fixes it. 2. Yes the default versions also lead to same issue. Just now I ran actually with the default version but with the change I wrote above. This shows the same result i.e. modules without any tests showing up in coverage report.
This is the run with pants default version for coverage and pytest-cov but modified
source
Copy code
./pants_from_sources test ::
15:37:11.91 [WARN] DEPRECATED: The autoflake plugin has moved to `pants.backend.python.lint.autoflake` (and from the `fmt` goal to the `fix` goal).
15:37:21.24 [INFO] Completed: Run Pytest - src/package-b/tests/test_package_b.py - succeeded.
15:37:21.24 [INFO] Completed: Run Pytest - src/package-a/tests/test_package_a.py - succeeded.

✓ src/package-a/tests/test_package_a.py succeeded in 1.26s (cached locally).
✓ src/package-b/tests/test_package_b.py succeeded in 1.31s (cached locally).

Name                                    Stmts   Miss  Cover
-----------------------------------------------------------
src/package-a/package_a/__init__.py         1      0   100%
src/package-a/package_a/main.py            16     16     0%
src/package-a/package_a/package_a.py        5      5     0%
src/package-a/package_a/settings.py         2      2     0%
src/package-a/tests/__init__.py             0      0   100%
src/package-a/tests/fake/__init__.py        0      0   100%
src/package-a/tests/fake/resource.py        1      0   100%
src/package-a/tests/test_package_a.py       8      0   100%
-----------------------------------------------------------
TOTAL                                      33     23    30%
e
Ok. I think tsticking to the issue is best, and unmuddying the waters by sticking with the Pants default coverage in the example repo helps keep the issue triage focused.
r
ok, I will push a new commit with pants default version.
e
And if you're willing to just dive in maybe this is an issue you are deep enough in to understand and fix?
r
yeah I was actually planning to. It’s just so many
rules
e
Hopefully the existing tests are enough guide rail to allow you to fix your case and not break prior / others.
👍 1