Hi me again. Just hit another issue (highly likely...
# general
a
Hi me again. Just hit another issue (highly likely me not configuring things right) Have the following Shared/tests/helpers/somefile.py Shared/tests/common/folder/myfile_test.py-> from helpers.somefile import function Shared/common/folder/myfile.py When i run pants test it throws NoModule exception for ‘helpers’ have a configured something wrong here. The tests and folder all have init file and have run tailor to ensure it generates the build file. Thanks in advance
e
Source roots are key here: https://www.pantsbuild.org/docs/source-roots#what-are-source-roots What does
./pants roots
say?
a
./pants roots . lambdas/get_session shared
folder structure
image.png
e
@abundant-analyst-12845 so you want `Shared/tests`to be a source root to be able to import
Shared/tests/helpers/somefile.py
as
helpers.somefile
-does that make sense?
a
my source root looks like this
Copy code
[source]
root_patterns = [
    "/lambdas/*",
    "/shared",
    # for conftest
    "/",
]
so thought tests would be able to picked up as well
e
Please try explicitly adding
/shared/tests
and report back and we can work from there to make sure you understand why this is needed
a
image.png
e
@abundant-analyst-12845, what is the full path of the
shared/session.py
you expect to be found for import? Whatver the answer, the prefix must be a source root.
That's the algorithm. You can crank out updates to your
source
configuration that way. import error -> what file do I expect to be providing that import -> is the prefix in
pants roots
.
Of course that's only for 1st party code. 3rdparty requires different tactics.
a
so here is the structure
full path
e
@abundant-analyst-12845 instead of feeding you answers I'd rather get you to learn the concept. Can you use the algorithm I described to solve the issue or is the algorithm confusing or is it not working?
👀 1
a
so I am not sure if I understood the concept but I was able to fix by mocking
correctly
i was mocking using
patch
using where the Class/Module was defined as opposed to where it was used.
e
Aha, ok so
shared.session
is not 1st party code; i.e.: you have no answer for what the full path of
shared/session.py
is because its code in some 3rdparty dependency? If so, then this makes sense, the algorithm I described is for 1st party code.
a
The full path of that from the root of the project is shared/shared/session/adaptor.py
e
Ok, and what does
./pants roots
say right now? Does it include
shared
still?
And is there a
shared/shared/__init__.py
? Implicit packages may not work in some cases (Pants doesn't care but some 3rdparty libraries do).
a
Sho am treating shared (first part) as namespace where as shared/shared as the project. And roots still shows shared as a root
e
Ok. Well without access to this repo its hard for me to say what's going on here.