<#18053 Coverage calculation using filter option d...
# github-notifications
q
#18053 Coverage calculation using filter option doesn't include files not part of tests Issue created by ShantanuKumar Describe the bug When calculating coverage using pants for python with option
filter
and
global_coverage = false
, only those modules are included which are part of pants' test run. Pants version 2.14.0 OS I have only checked on MacOS Additional info It can be reproduced using the code in this repo
Copy code
./pants test ::
13:37:31.85 [INFO] Initializing scheduler...
13:37:32.19 [INFO] Scheduler initialized.
13:37:37.87 [INFO] Completed: Run Pytest - src/package-b/tests/test_package_b.py succeeded.
13:37:37.87 [INFO] Completed: Run Pytest - src/package-a/tests/test_package_a.py succeeded.

āœ“ src/package-a/tests/test_package_a.py succeeded in 1.11s (cached locally).
āœ“ src/package-b/tests/test_package_b.py succeeded in 0.60s (cached locally).

Name                                    Stmts   Miss  Cover
-----------------------------------------------------------
src/package-a/package_a/__init__.py         1      0   100%
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       6      0   100%
-----------------------------------------------------------
TOTAL                                       8      0   100%
This issue doesn't show up when directly running pytest with
--cov
. There are files with no tests for them but are part of coverage calculation.
Copy code
pytest --cov=src/package-a src/package-a/tests
======================================= test session starts ========================================
platform darwin -- Python 3.9.0, pytest-7.0.1, pluggy-1.0.0
rootdir: /Users/developer/shantanu/pants-multi-poetry
plugins: asyncio-0.20.3, mock-3.10.0, hypothesis-6.56.0, anyio-3.6.2, dash-2.6.0, cov-3.0.0
asyncio: mode=strict
collected 1 item                                                                                   

src/package-a/tests/test_package_a.py .                                                      [100%]

---------- coverage: platform darwin, python 3.9.0-final-0 -----------
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       6      0   100%
-----------------------------------------------------------
TOTAL                                      31     23    26%
pantsbuild/pants