运行nosetests时,django-nose runner不会向--with-django
提供nosetests
选项,因此在尝试访问URL时我的鼻子+斜纹测试失败:
./manage.py test
...
raise BrowserStateError("cannot go to '%s'" % (url,))
BrowserStateError: cannot go to 'http://127.0.0.1:8088/admin/'
----------------------------------------------------------------------
Ran 2 tests in 0.166s
FAILED (errors=1)
当我手动提供--with-django
或设置NOSE_WITH_DJANGO=1
环境变量时,我的测试成功运行,但之后我收到以下异常:
$ ./manage.py test --with-django
...
Ran 2 tests in 0.199s
OK
...
AttributeError: type object 'Template' has no attribute 'original_render'
nosetests --with-django
成功运行测试
答案 0 :(得分:0)
原来问题是我使用了tddspry
django-nose
并且他们都有自己类似的setup / teardown插件,所以我将django-nose TestRunner子类化并从默认设置中删除了该插件。
要解决此问题,请从官方git repository,最新稳定tddspry
from PyPI安装最新django-nose
,并将dddpry TestSuiteRunner添加到Django设置,如下所示:
TEST_RUNNER = 'tddspry.django.runner.TestSuiteRunner'