I've got a silly question (I think): *How do I run...
# general
s
I've got a silly question (I think): How do I run (or list) all tests that cover a
python_source
?
Copy code
# The most intuitive, but doesn't work
pants test source.py

# These don't work
pants dependents --transitive --filter-target-type=python_tests source.py
pants filedeps --transitive --filter-target-type=python_tests source.py

# This seems to work, but isn't clean
pants dependents source.py | grep _test.py | xargs pants test
h
pants dependents
doesn’t run tests, it lists dependents, so that is behaving as expected.
pants test source.py
doesn’t do anything because
source.py
isn’t a test, although I can see how that would be intuitive.
Copy code
pants dependents --transitive --filter-target-type=python_tests source.py | xargs pants test
Is I think the cleanest way to do this right now
There is
pants --changed-since=main --changed-dependents=transitive test
for running all tests that cover changed files, but nothing to cover a specific named file
although that is useful so I can see supporting it
s
Ah sorry @happy-kitchen-89482, let me clarify. I don't expect
pants dependents --transitive --filter-target-type=python_tests source.py
to run tests. But it doesn't list any targets:
Copy code
# This works as expected:
$ pants dependents --transitive source.py
other_source.py:sources
source_test.py:tests

# Filtering by target-type works with `list`:
$ pants list : --filter-target-type=python_test
source_test.py:tests

# Doesn't print anything for filtered dependents:
$ pants dependents --transitive --filter-target-type=python_tests source.py
$
h
Oh right, because
--filter
applies to the input targets, not the output targets…
🤦‍♂️ 1
So you can move the
--filter
on to the second invocation
the
xargs pants test
one
s
Oh right, because
--filter
applies to the input targets, not the output targets
I suppose this makes sense, just a bit unintuitive 👍
h
Well, it applies to all goals, most of which don’t output targets. It’s confusing when the goal happens to output targets
We could add something like
--output-filter
to those goals
👍 2
h
+1 for
—output-filter
h
As always, PRs welcome!