Hey, am seeing something weird and wanted to see i...
# general
r
Hey, am seeing something weird and wanted to see if anyone had any ideas. We're trying to structure a python package like this:
Copy code
mypackage/__init__.py
mypackage/hello.py
mypackage/tests/test_hello.py
However, when we try to run the test file using pants, it complains it cannot import module
mypackage.hello
. However,
pants dependencies --transitive mypackage/tests/test_hello.py
shows all `mypackage/hello.py`'s dependencies as well, only the module itself is missing. So it seems like pants is correctly inferring that
test_hello.py
depends on
hello.py
but then not adding
hello.py
in as a dependency?
b
How does the test import the package? As a normal import?
r
Yep,
from mypackage.hello import hello_world
BUILD
file in
mypackage
has a
python_sources
(among other stuff) and the
BUILD
in tests only has
python_tests
and can confirm
mypackage
is a source root
ooh wait, maybe the source root should be the folder on top of
mypackage
(which is the root for the repo)?
b
Yeah, that sounds like the problem. if there’s a path
/foo/bar.py
and
/foo
is a source root, then
import bar
works to load that file, not
import foo.bar