https://pantsbuild.org/ logo
l

lemon-helicopter-73409

03/09/2023, 4:53 PM
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

happy-kitchen-89482

03/09/2023, 5:18 PM
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

lemon-helicopter-73409

03/09/2023, 5:23 PM
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

happy-kitchen-89482

03/09/2023, 5:39 PM
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

lemon-helicopter-73409

03/09/2023, 5:40 PM
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

happy-kitchen-89482

03/09/2023, 5:42 PM
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

lemon-helicopter-73409

03/09/2023, 5:44 PM
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

happy-kitchen-89482

03/09/2023, 6:01 PM
SG
l

lemon-helicopter-73409

03/09/2023, 6:02 PM
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

happy-kitchen-89482

03/09/2023, 10:26 PM
W00t! that's great
6 Views