gpt4 book ai didi

Django-nose 不会运行单独的 TestCase 类

转载 作者:行者123 更新时间:2023-12-02 04:47:23 27 4
gpt4 key购买 nike

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

最佳答案

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

manage.py test someapp.tests:SomeTestClass

<path_to_python_module>:<class_name>

关于Django-nose 不会运行单独的 TestCase 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19526620/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com