Hi, I have a case in which each project has its o...
# general
h
Hi, I have a case in which each project has its own
test
folder:
Copy code
proj_a (proj)
- proj_a (src)
  - __init__.py
  - main.py
  - ...
- test
  - test_a.py
  - test_b.py
  - ...
prob_b
- proj_b (src)
  - ...
- test
  - ...
...
However, in each
test
folder, there are tests that import adjacent helper files. Is this expected to work? If so, then I guess that the import should be something like
from test import helper_a
? In that case, each project has a
test
"package"? Is there a guarantee that each of them will refer the
test
folder for the same project, rather than another one and rather than merging them? (thanks in advance ๐Ÿ™ )
๐Ÿงต
h
What are your source roots in this example?
If they are
proj_a/
,
proj_b
, so that
test
is a top-level package, then you have a namespacing problem
this is a problem at the Python level, regardless of Pants.
If you have two
test/util.py
then they will collide
this is why it's a good idea to namespace your tests under each source root
so that there is no ambiguity
That said, Pants dep inference can now figure this out correctly
thanks to this PR:
Which will be in 2.16
So as long as you don't have an actual module name conflict, the sandbox should contain the right files
But the general answer to your question "Is there a guarantee that each of them will refer the test folder for the same project, rather than another one and rather than merging them?" is no, at the Python level, irrespective of Pants
(unless you treat every project as an entirely separate "repo" from a Python perspective, which is what #17931 is supposed to emulate)