I now run into `django.core.exceptions.AppRegistry...
# general
f
I now run into
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
when loading required apps via conftest.py hook ... right now I'm rather confused about this since apps are correctly declared in settings at runtime ... 🤔 any hints? 🙏
e
I was fighting few of these lately as well… Can you verify that conftest is added to the sandbox and is executed? Are you using “django settings” env var or calling “settings setup” explicitly?
f
yeah, conftest is getting executed, I can reach my breakpoint within. I'm actually using conftest to hook in to dynamically load settings - like in the django example repository
anyways, not caused by pants, I'm pretty sure
just need to figure a way how to make it work
s
in our repo we put the following in our conftests:
Copy code
os.environ['DJANGO_SETTINGS_MODULE'] = 'path.to.test.settings'
django.setup()
and then have all the apps listed in
INSTALLED_APPS
in
path/to/test/settings.py
. this works reliably for us
you can end up with weird failures if you expect Pants to infer a dependency and it fails to do so. we had to do some tricks: • Make sure the full module path to the settings file is explicitly listed in the source of
conftest.py
, otherwise Pants won’t see it • In your
INSTALLED_APPS
, use the full names of your
AppConfig
subclasses:
Copy code
# Instead of this:
INSTALLED_APPS = (
  "apps.app1",
  "apps.app2",
)

# Do this:
INSTALLED_APPS = (
  "apps.app1.apps.App1Config",
  "apps.app1.apps.App2Config",
)
if you don’t do point 2, Pants won’t include the `apps.py`s in your test sandboxes. you could probably fix it another way by declaring explicit dependencies from each app’s
__init__.py
to its
apps.py
f
Ok, I’ll give it a try, thx!