test.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 シェルで実行すると、次のようになります。
$ ./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 でアクティブです。
管理コマンドの実行中にこのエラー アサーションが表示されるのはなぜですか?