2

尝试使用 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 时才会失败。

4

1 回答 1

5

如果您使用的是nose,请输入模块的名称(通常为tests)、冒号和测试类

manage.py test someapp.tests:SomeTestClass

<path_to_python_module>:<class_name>

于 2013-10-22T19:37:46.893 回答