Using Pycharm, I get some different results, then running commands from the terminal. I noticed that after I updated my view, I got a "Apps aren't loaded yet" exception ONLY when running the test from the IDE.
If I run the test via terminal "python3 manage.py test", there is no issue.
IDE runs tests no problem with this view file
def wine_data(request):
return HttpResponse("<html><title>Wine Data</title></html>")
If I change the view file to this:
def wine_data(request):
return render(request, 'wine_data.html')
I get this error (only when ran from IDE)
/home/codeamend/Projects/python/OldBullTavern/venv/bin/python /opt/pycharm-professional/helpers/pycharm/utrunner.py /home/codeamend/Projects/python/OldBullTavern/obt/wine/tests.py true Testing started at 11:38 AM ...
Error Traceback (most recent call last): File "/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/utils.py", line 86, in getitem return self._engines[alias] KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/home/codeamend/Projects/python/OldBullTavern/obt/wine/tests.py", line 16, in test_wine_data_loads_correct_html response = wine_data(request) File "/home/codeamend/Projects/python/OldBullTavern/obt/wine/views.py", line 6, in wine_data return render(request, 'wine_data.html') File "/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/shortcuts.py", line 67, in render template_name, context, request=request, using=using) File "/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/loader.py", line 96, in render_to_string template = get_template(template_name, using=using) File "/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/loader.py", line 26, in get_template engines = _engine_list(using) File "/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/loader.py", line 143, in _engine_list return engines.all() if using is None else [engines[using]] File "/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/utils.py", line 110, in all return [self[alias] for alias in self] File "/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/utils.py", line 110, in return [self[alias] for alias in self] File "/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/utils.py", line 101, in getitem engine = engine_cls(params) File "/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/backends/django.py", line 31, in init options['libraries'] = self.get_templatetag_libraries(libraries) File "/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/backends/django.py", line 49, in get_templatetag_libraries libraries = get_installed_libraries() File "/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/backends/django.py", line 132, in get_installed_libraries for app_config in apps.get_app_configs()) File "/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/apps/registry.py", line 137, in get_app_configs self.check_apps_ready() File "/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/apps/registry.py", line 124, in check_apps_ready raise AppRegistryNotReady("Apps aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Process finished with exit code 0
Any Ideas?
manage.py test
). How are you attempting to run it (from the IDE console or by right clicking it)? I guess you have Pycharm community (unpaid) edition? – CristiFati