Hello! We want to use pants to run only tests whos...
# general
e
Hello! We want to use pants to run only tests whose transitive dependents have changed. Unfortunately we’re running into a problem where if any files in a python_sources target change, any tests that depend on any of the files in that python_sources target are listed in
pants --changed-since=main --changed-dependents=transitive list
even if the files they depend on haven’t changed. Basically, it seems like the sources are being treated as a group rather than separately. I don’t particularly want to go around splitting every single python_sources target — is there anything else we can do? Is this behavior expected?
w
Can you make a repro repo? If I'm understanding this, you have
Copy code
python_sources(*.py)
- foo.py
- bar.py
and then you change foo, and bar's tests run too?
e
yeah that’s exactly correct
I can make a minimal repro and file an issue if this isn’t expected
w
e
These aren’t third-party deps
w
Yeah, the hint implies
target_generator
which python_sources is. I've never looked through the transitive dependency code, but this is surprising off the top of my head
Like, it's third-party that it has an issue with, but who knows if that comment is stale. From an expectation point of view, I would absolutely expect what you're trying to work with good granularity on first-party code. If you can make a repro, I think it would be easier to dig in
e
Oh interesting, good catch
I’ll try to make a repro and file an issue tomorrow. Is it alright if I assign that to you?
Or would you prefer I just cc
w
Just cc - someone else might already know about this
h
Yeah, that is mildly surprising to me, since the generated single-file target and its transitive deps should be what's in play
☝️ 1
e
Hm I made the minimal foo/bar and wasn't able to reproduce, let me poke around and see if the problem isn't just that our repo has absurdly intertwined dependencies
Thanks all for the prompt response! If I can get a clean repro I will file an issue, and in the meantime please assume I got this one wrong and our problem lies elsewhere (likely either intertwined dependencies or deciding on which ref to pass to --changed-since)
👍 1
w
❤️ 1
e
I'm pretty sure I got to the bottom of it. In CI, we were doing
--changed-since=origin/main
to run tests affected by a PR, which isn't quite right. What we really wanted was
--changed-since="$(git merge-base HEAD origin/main)"
so that we only run the tests changed relative to the merge base, not unrelated changes to main that got merged while we were working on the PR. If you think other people might fall into this trap, I'm happy to send a PR adding this tip to the --changed-since docs. Otherwise, I'm just glad that we're not running oodles of tests anymore 🙂
w
Yeah, sure, doc improvements are always welcome. You could also look into pants.toml
cli.alias
to setup the ones you want, and recommend your team use those internally to make sure it’s locked down
👀 1
e
I did end up finding a different bug where any change to a BUILD file (even whitespace) marks all targets in the BUILD file as changed. I suspect this may be a harder fix if pants is currently doing purely file-level inspection, but it has some unfortunate implications, e.g. touching a BUILD file in a high up directory can cause nearly every target in the repo to show up as changed and therefore run way more tests than needed. Filed as https://github.com/pantsbuild/pants/issues/23307