Stupid Question: should /foo/bar_test.py depend on...
# general
a
Stupid Question: should /foo/bar_test.py depend on /foo/bar.py? Right now this is only true if the test module imports the tested code, but in a Django repository that's often not true. That means that when I change the code for an endpoint and run
pants test --changed-since HEAD
no tests are run.
b
Probably not out-of-the-box, but our Django plugin could likely make that inference, if enabled
a
Oh, good call. I was thinking it felt more like a plugin problem.
I'm not currently using the django plugin, where would i find it?
h
The django plugin is a work in progress, and it currently only handles deps between migrations
But there are django-friendly features in the regular python plugin
Specifically
will read a literal string "foo.bar.baz" as a dependency on that module
So if your tests use that, or use a settings.py that uses that...
a
Ja, we use that. The challenge I have here is that endpoint_test.py doesn't import endpoint.py so change detection for tests doesn't work
Or am I missing your point?
h
how does endpoint_test.py test endpoint.py? It must bring its code into scope somehow...
if not via import then via a settings.py?
a
No, by calling the http endpoint via the Django test client. It's a whole thing,I have opinions.... but the upshot is that I'd like to consider foo.py as a dependency of foo_test.py by convention
h
aha
so right now that requires a manual dep, which is annoying
But you could write a custom plugin that adds that as an inferred dep
Is foo_test.py a sibling of foo.py, or do they live under different src and test dirs?
a
Yeah, they're siblings.
h
If you feel like contributing this as a new feature gated by an option in
[python-infer]
, I think it even makes sense in core
I am hard pressed to think of an example of where foo.py is not a dep of foo_test.py
💯 1
a
Okay, I might go spelunking in the inference code
b
Does
foo_test.py
also have the option of calling http endpoints from other files (eg
bar.py
) or is the client/server limited to only those in
foo.py
?
a
It's not limited, it's purely conventional, which is why I'm happy with the idea of a plugin
But in practice, we're calling only the foo endpoint from that file.
b
Hm, yeah, if it’s not limited, anything in pants itself would need to depend on everything, I would think (at least by default), to try to ensure tests within and without behave the same
a
Before I go off on a tangent, inventing solutions to non-problems, ought i to be able to run tests for changed targets in pants? ie, if 'foo.py' has changed, and 'foo_test.py' imports foo, then run foo_test?
b
Yes, with one or other of the non-default value for --changed-dependents, I think https://www.pantsbuild.org/docs/reference-changed
a
aha! changed dependents. I was trying changed-since with --dependees-transitive. Thanks for the breadcrumb!