测试.py
# write code to test the views.
from django.test import Client
# import nose for tests.
import nose.tools as noz
class TestSettings(object):
""" test the nose test related setup """
def setup(self):
self.client = Client()
def testTestUser(self):
""" Tests if the django user 'test' is setup properly."""
# login the test user
response = self.client.login(username=u'test', password=u'test')
noz.assert_equal(response, True)
从管理命令运行此代码时,会给出以下输出:
$ ./manage.py test <app-name>
nosetests --verbosity 1 <app-name>
Creating test database for alias 'default'...
F
======================================================================
FAIL: Tests if the django user 'test' is setup properly.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/<python-sitepackages-dir-path>/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "<application-path>/tests.py", line 28, in testTestUser
noz.assert_equal(response, True)
AssertionError: False != True
----------------------------------------------------------------------
Ran 1 test in 0.008s
FAILED (failures=1)
Destroying test database for alias 'default'...
现在通过 django shell 运行时相同的命令给出以下内容:
$ ./manage.py shell
Python 2.6.6 (r266:84292, Sep 11 2012, 08:28:27)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.test import Client
>>>
>>> import nose.tools as noz
>>>
>>> client = Client()
>>> response = client.login(username=u'test', password=u'test')
>>> noz.assert_equal(response, True)
>>>
>>>
>>> response
True
>>>
用户 'test' 在 django 中对于当前场景处于活动状态。
为什么我在运行管理命令时收到此错误断言?