尝试使用django-nose
运行单个TestCase时出错$ ./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
时,它会成功运行someapp / tests.py中的所有TestCase;只有在尝试运行单个TestCase时才会失败。
答案 0 :(得分:5)
如果您正在使用nose,请输入模块的名称(通常为tests
),冒号和测试类
manage.py test someapp.tests:SomeTestClass
<path_to_python_module>:<class_name>