嘗試使用Django的鼻子Django的鼻子會不會運行單個測試用例類
$ ./manage.py test someapp.ModelTest
nosetests someapp.ModelTest --nologcapture --verbosity=1
Creating test database for alias 'default'...
E
======================================================================
ERROR: Failure: AttributeError ('module' object has no attribute 'ModelTest')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/nose/loader.py", line 402, in loadTestsFromName
module = resolve_name(addr.module)
File "/usr/lib/python2.7/site-packages/nose/util.py", line 321, in resolve_name
obj = getattr(obj, part)
AttributeError: 'module' object has no attribute 'ModelTest'
----------------------------------------------------------------------
Ran 1 test in 0.003s
FAILED (errors=1)
需要注意的是,當我運行$ ./manage.py test someapp
它成功運行所有的TestCase的運行一個單獨的測試用例時,我得到一個錯誤在someapp/tests.py中;只有在試圖運行單個TestCase時纔會失敗。
它只是一個導入錯誤的名字,但它不可能無需查看代碼的其餘部分即可知道問題所在。我會想象你在你的模型,管理或視圖文件中導入了一個混亂的導入? –
[如何用django-nose運行單個測試或單個TestCase?](http://stackoverflow.com/questions/18834188/how-to-run-a-single-test-or-single-testcase -with-django-nose) – kolen