首页 文章

仅使用pycharm的Django测试错误 - 不是终端|应用尚未加载

提问于
浏览 1939
11

使用Pycharm,我得到一些不同的结果,然后从终端运行命令 . 我注意到,在我更新了我的视图后,只有在从IDE运行测试时才会出现“尚未加载应用程序”的异常 .

如果我通过终端“python3 manage.py test”运行测试,则没有问题 .

IDE运行测试此视图文件没有问题

def wine_data(request):
    return HttpResponse("<html><title>Wine Data</title></html>")

如果我将视图文件更改为:

def wine_data(request):
    return render(request, 'wine_data.html')

我收到此错误(仅在从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测试从上午11:38开始...错误回溯(最近一次调用最后一次):文件“/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/utils . py“,第86行,在getitem中返回self._engines [alias] KeyError:'django'在处理上述异常期间,发生了另一个异常:Traceback(最近一次调用last):File”/ home / codeamend / Projects / python / OldBullTavern / obt / wine / tests.py“,第16行,在test_wine_data_loads_correct_html响应= wine_data(请求)文件”/home/codeamend/Projects/python/OldBullTavern/obt/wine/views.py“,第6行,在wine_data中返回渲染(request,'wine_data.html')文件“/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/shortcuts.py”,第67行,在render template_name中,context ,request = request,using = usi ng)文件“/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/loader.py”,第96行,在render_to_string中模板= get_template(template_name,using = using )文件“/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/loader.py”,第26行,在get_template engines = _engine_list(using)File“/ home /codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/loader.py“,第143行,在_engine_list中返回engines.all()如果使用的是其他[引擎[使用] ]]文件“/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/utils.py”,第110行,全部返回[self [alias] for alias in self]文件“/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/utils.py”,第110行,作为回报[self [alias] for selfias in self ]文件“/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/ut ils.py“,第101行,在getitem引擎= engine_cls(params)文件”/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/backends/django.py “,第31行,在init选项中['libraries'] = self.get_templatetag_libraries(libraries)文件”/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/backends /django.py“,第49行,在get_templatetag_libraries libraries = get_installed_libraries()文件”/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/template/backends/django.py “,第132行,在apps.get_app_configs()中的app_config的get_installed_libraries中)文件”/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/apps/registry.py“,第137行,在get_app_configs中self.check_apps_ready()文件“/home/codeamend/Projects/python/OldBullTavern/venv/lib/python3.5/site-packages/django/apps/registry.py”,第124行,在check_apps_ready中AppRegistryNotReady(“应用程序ar尚未加载 . “)django.core.exceptions.AppRegistryNotReady:尚未加载应用 . 进程以退出代码0结束

有任何想法吗?

2 回答

  • 1

    您的测试是否具有正确的“工作目录”值和“目标”?

    我在Behave测试中遇到了类似的问题......

  • 0

    这似乎是一个虚拟环境加载错误 . 您是否已将正确的虚拟环境应用于测试环境?查看此文章并尝试再次运行它 . http://exponential.io/blog/2015/02/10/configure-pycharm-to-use-virtualenv/

    另外在另一个注意事项上,如果你是正确的模板加载或GET请求,请随时查看my tutorial .

相关问题