https://pantsbuild.org/ logo
#general
Title
# general
p

plain-carpet-73994

05/01/2021, 12:37 AM
Hey - have an odd issue with some tests. I have a package called
utils
with an
__init__.py
that looks like this:
Copy code
from .require import require
from .foo import foo

__all__ = ['require', 'foo']
and the
foo.py
and
require.py
files exist and can be imported from other packages as expected (e.g.
import utils.require
). I added a unit test for
foo
which does not use
require
.
require
currently doesn't have any unit tests. My BUILD file is super simple:
Copy code
python_library()

python_tests(name='test')
When I try to run the tests in
utils
I get:
Copy code
E   ModuleNotFoundError: No module named 'utils.require'
My theory is that since I'm not using
require
in any tests that file doesn't get put in my sandbox so it's not available and I therefore get the error. But adding a
dependencies=['./:utils']
to my
python_tests
target doesn't help either. Having an
__init__.py
that exports a bunch of things some of which may not have unit tests seems fairly common so I suspect I'm doing something wrong. Any advice?
h

hundreds-father-404

05/01/2021, 12:38 AM
Hey, check out the tool tip on https://www.pantsbuild.org/docs/python-backend about content in your
__init__.py
files, I suspect that this is the issue We still have a TODO to make the default more sensible
p

plain-carpet-73994

05/01/2021, 12:39 AM
that looks like what I was looking for. Thanks!
❤️ 1
h

hundreds-father-404

05/01/2021, 12:45 AM
Pardon the confusion from this gotcha. We've fixed a lot of the gotchas the past few months, but this remains one for sure (Do please continue to share feedback on things like this. Even if you are able to figure it out without asking for help, it is still helpful to share what was confusing. We want Pants to be really seamless to adopt)
p

plain-carpet-73994

05/01/2021, 1:00 AM
will do. Thanks for all your work on it. Really enjoying it. As a former Bazel user I can say that I'm liking Pants much better.
🙌 2
5 Views