擅长:python、mysql、java
<p>看起来它没有继承基测试类,所以它不会在测试之前调用setup方法。我建议继承Django的TestCase类,如<a href="https://docs.djangoproject.com/en/1.5/topics/testing/overview/" rel="nofollow">the Django documentation on testing</a>。在这种情况下,它看起来像这样:</p>
<pre><code># write code to test the views.
from django.test import Client
import unittest
# import nose for tests.
import nose.tools as noz
class TestSettings(unittest.TestCase):
""" test the nose test related setup """
def setUp(self): # Note that the unittest requires this to be setUp and not setup
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)
</code></pre>