Hello again! So, I’m having a hard time getting t...
# general
l
Hello again! So, I’m having a hard time getting tests to run with django. The repo is here: https://github.com/xuru/monolith-to-monorepo/tree/pants_baseline, and this the error it’s giving me:
Copy code
ImportError: No module named 'config'

pytest-django could not find a Django project (no manage.py file could be found). You must explicitly add your Django project to the Python path to have it picked up.
Somehow pytest-django can’t figure out where
config/settings
is? Any help is appreciated!
h
Have you looked at https://github.com/pantsbuild/example-django ? It demos a bunch of the wiring needed
Specifically, this is how it points pytest-django to your settings.py:
(it demonstrates how to do this for multiple different settings.py/services in the same repo)
I guess in this case it actually programmatically sets your settings, but you can simply import them instead
l
I think part of the problem is that it’s failing to load the
config
module in the pytest-django plugin before it ever gets to the conftest.py, but I could be wrong.
The
config
,
mtom
and
manage.py
are at the top level of the repo, and
mtom/BUILD
is where I set the
python_tests
target.
yeah, verified that it doesn’t get to the
conftest.py
file
h
Hmm, so the debugging path is: see how your setup differs from the example repo, and start eliminating differences.
At least temporarily, for debugging purposes
l
I think I just figured it out
I added
dependencies=['config']
to the
python_tests
I thought it would figure that out, but I guess I had to be explicit
Getting lots of warnings about multiple targets owning the settings files now though…
h
conftest.py
is useful for loading different settings in different tests, but for now there are also other ways to tell pytest-django about your settings, e.g., in an env var (that you will have to punch through to the test via this option: https://www.pantsbuild.org/docs/reference-subprocess-environment#env_vars
Ah, great
progress
what are the targets in your config BUILD file?
l
oh, this is all me. When I was trying to get things working, I moved around some targets, and I just need to clean it up. Let me clean it up and see if we are all good now
h
SG
l
ok, got it working! Thanks for the help. Let me get this commited to the repo, and I can show you what I changed.
Had to pull in dependencies like this:
dependencies=["//:req", 'config'],
and give the
python_tests
target a name…
h
W00t! that's great