mercredi 26 août 2015

Django: Apps Aren't Loaded Yet Error under Pytest

I'm trying to run some tests I wrote for my Django app using pytest, however I'm encountering the following error:

==================================================== FAILURES =====================================================
_____________________________________________________ tester ______________________________________________________

request = <FixtureRequest for <Function 'tester'>>

    def tester(request):
        #return render_to_response('agentex/test.html')
        return render(request, 'agentex/test.html', {})

agentex/views.py:1875: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/shortcuts.py:67: in render
template_name, context, request=request, using=using)
../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/template/loader.py:98: in render_to_string
template = get_template(template_name, using=using)
../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/template/loader.py:35: in get_template
return engine.get_template(template_name, dirs)
../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/template/backends/django.py:30: in get_template
return Template(self.engine.get_template(template_name, dirs))
../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/template/engine.py:167: in get_template
template, origin = self.find_template(template_name, dirs)
../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/template/engine.py:141: in find_template
source, display_name = loader(name, dirs)
../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/template/loaders/base.py:13: in __call__
return self.load_template(template_name, template_dirs)
../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/template/loaders/base.py:17: in load_template
template_name, template_dirs)
../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/template/loaders/app_directories.py:36: in load_template_source
for filepath in self.get_template_sources(template_name, template_dirs):
../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/template/loaders/app_directories.py:26: in get_template_sources
template_dirs = get_app_template_dirs('templates')
../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/utils/lru_cache.py:125: in wrapper
result = user_function(*args, **kwds)
../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/template/utils.py:122: in get_app_template_dirs
for app_config in apps.get_app_configs():
../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/apps/registry.py:137: in get_app_configs
self.check_apps_ready()
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

 self = <django.apps.registry.Apps object at 0x103a31c90>

    def check_apps_ready(self):
        """
        Raises an exception if all apps haven't been imported yet.
        """
        if not self.apps_ready:
            raise AppRegistryNotReady("Apps aren't loaded yet.")
E           AppRegistryNotReady: Apps aren't loaded yet.

../../../anaconda/envs/agentex/lib/python2.7/site-packages/django/apps/registry.py:124: AppRegistryNotReady

I'm not entirely certain of a) what's causing this error and, more importantly, b) how to go about fixing it.

A few weeks ago the app was upgraded from Django 1.4 to Django 1.8. All other aspects of the app work perfectly - no errors like this are thrown in operation (i.e. attempting to run pytest is the only time that it is encountered). The deprecated tags and syntax were fixed (they immediately threw errors) after the upgrade.

Interestingly enough, running the tests with Django/Python's own unittest don't return these errors, perhaps because of the command python manage.py test required to run the testing suite.

I hope somebody can help!


EDIT #1: Commenting the function tester out of views.py fixes the issue and pytest now runs, however I'm not sure why it was disliking tester - it's never done so before.

Aucun commentaire:

Enregistrer un commentaire