Django测试客户端响应上下文无 [英] Django test client response context None

查看:52
本文介绍了Django测试客户端响应上下文无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将我的Django应用程序从开发机器(OS X,Python 2.6.5,Django 1.2.3)移到了登台服务器(Ubuntu VM,Python 2.6.6,Django 1.2.3)。

I have moved my Django app from my development machine (OS X, Python 2.6.5, Django 1.2.3) to a staging server (Ubuntu VM, Python 2.6.6, Django 1.2.3).

如果我现在在登台服务器上运行测试套件,则使用Django TestClient时两个测试将失败,因为response.context为None(但response.content是正确的)。

If I now run my test suite on the staging server, two tests fail when using the Django TestClient because response.context is None (but response.content is correct).

例如:

self.assertEquals(self.session.pk, response.context['db_session'].pk)

这些测试用例在开发机器上通过

These test cases pass on the development machine.

有人遇到过类似的问题吗?

Has anybody encountered similar problems?

推荐答案

添加测试设置语句。

import django
django.test.utils.setup_test_environment() 

通过以下链接查找更多详细信息:
http://jazstudios.blogspot.com/2011/01/django-testing-views.html

Find more details by following my link: http://jazstudios.blogspot.com/2011/01/django-testing-views.html

这篇关于Django测试客户端响应上下文无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆