Hello! In version 1.X of Pants, the target `python...
# general
m
Hello! In version 1.X of Pants, the target
python_tests
has the property `coverage`:
Copy code
coverage: A list of the module(s) you expect for this test target to cover. Usually, Pants and pytest-cov can auto-discover this if your tests are located in the same folder as the python_library code, but this is useful if the tests are not collocated.
However, in version 2.X, I noticed there’s no such property. What’s the equivalent one in Pants 2.X?
h
m
Ahh,
--coverage-py-filter
, correct?
But what I wanted is filtering per
python_test
target
--coverage-py-filter
applies to all targets, right?
h
Yeah if you want to filter rather than all files in the chroot, you use that option. Although note that pants runs in a chroot (tmpdir), so it already only reports on files in the transitive closure of your particular tests https://www.pantsbuild.org/docs/python-test-goal#coverage
m
And can’t we apply the coverage to just a subset of the transitive closure? 😅
This is the scenario we have: We have multiple stacks. One of them is shared across all the others (i.e. a
common
stack). As of now, when we test the coverage of a particular stack (let’s say
stackA
), the
common
stack is considered as well. However, we just want to assert the coverage limit for
stackA
h
Yes, via that option One of the big differences with the redesign is that it was really tricky to get the coverage field on Python_tests to work correctly and the results were almost always under-reporting. You can still report on as little as you want, but now it's more obvious
Cool, yeah, you'd use that option. Reminder that you can more permanently set it via config file or env var. https://www.pantsbuild.org/docs/options#setting-options
m
OK, but now I need to invoke
pants
for each of the stacks, with a different value for
--coverage-py-filter
, right?
h
Could you still do one run, but allowlist everything except for common? Note that you can pass multiple values for --filter, it's a list option
--coverage-py-filter='["stackA", "stackB"]'
m
I see! Let me give that a try then
Thanks 🙏
❤️ 1
h
You're welcome! Also reminder that Pants calls
coverage combine
to merge all the distinct test results into one single report. So, if you're running all your tests, it may be useful to still include common The results would be misleading when you do a run locally on a subset of your tests, but that's probably fine - only care about the number in CI that runs over everything
m
The issue I’m having is that common is included in the reports, even though we’re mocking any references to other stacks 🤔. Previously, when we were using 1.28, we were using the property
coverage
in
python_test
, as this allowed us to apply the coverage threshold per stack. I was hoping the behaviour would stay the same, however, you raised the concern that the coverage could not be correct. I will try the
coverage-py-filter
option.
👍 1