如果 setUpClass 失败,如何查看失败测试的名称?
How can I see name of failed tests if setUpClass is failed?
请帮帮我。
如果 setUpClass 失败,如何查看失败测试的名称?
示例:
import unittest
import nose
class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
print "Execute setup class!"
assert 10 != 10
def test_1(self):
"""Test # 1"""
pass
def test_2(self):
"""Test # 2"""
pass
if __name__ == "__main__":
nose.run(argv=[" ", "work_temp.py", "--verbosity=2", "--nocapture"])
如果 SetUp 中的某些断言失败 - 我有这样的错误输出(看不到测试名称):
======================================================================
ERROR: test suite for <class 'tests.work_temp.Test'>
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/nose/suite.py", line 209, in run
self.setUp()
.....................................................................
return func()
File "/home/temp/PycharmProjects/Safo/tests/work_temp.py", line 9, in setUpClass
assert 10 != 10
AssertionError
----------------------------------------------------------------------
Ran 0 tests in 0.001s
FAILED (errors=1)
我希望看到这样的东西:
Test # 1 ... FAILED
Test # 2 ... FAILED
您在为测试方法创建容器 class 时抛出断言异常,并且在这种情况下唯一合乎逻辑的行为不是 运行 底层测试。这就是 nose 所做的,但它这样做是为了符合 python unittest specifications:
If an exception is raised during a setUpClass then the tests in the class are not run and the tearDownClass is not run.
如果您愿意走出 unittest 库,您可以通过像这样修改代码来获得您想要的行为:
from nose.tools import with_setup
def setup_func():
print "Execute setup class!"
assert 10 != 10
@with_setup(setup_func)
def test_1():
"""Test # 1"""
pass
@with_setup(setup_func)
def test_2():
"""Test # 2"""
pass
请帮帮我。 如果 setUpClass 失败,如何查看失败测试的名称?
示例:
import unittest
import nose
class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
print "Execute setup class!"
assert 10 != 10
def test_1(self):
"""Test # 1"""
pass
def test_2(self):
"""Test # 2"""
pass
if __name__ == "__main__":
nose.run(argv=[" ", "work_temp.py", "--verbosity=2", "--nocapture"])
如果 SetUp 中的某些断言失败 - 我有这样的错误输出(看不到测试名称):
======================================================================
ERROR: test suite for <class 'tests.work_temp.Test'>
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/nose/suite.py", line 209, in run
self.setUp()
.....................................................................
return func()
File "/home/temp/PycharmProjects/Safo/tests/work_temp.py", line 9, in setUpClass
assert 10 != 10
AssertionError
----------------------------------------------------------------------
Ran 0 tests in 0.001s
FAILED (errors=1)
我希望看到这样的东西:
Test # 1 ... FAILED Test # 2 ... FAILED
您在为测试方法创建容器 class 时抛出断言异常,并且在这种情况下唯一合乎逻辑的行为不是 运行 底层测试。这就是 nose 所做的,但它这样做是为了符合 python unittest specifications:
If an exception is raised during a setUpClass then the tests in the class are not run and the tearDownClass is not run.
如果您愿意走出 unittest 库,您可以通过像这样修改代码来获得您想要的行为:
from nose.tools import with_setup
def setup_func():
print "Execute setup class!"
assert 10 != 10
@with_setup(setup_func)
def test_1():
"""Test # 1"""
pass
@with_setup(setup_func)
def test_2():
"""Test # 2"""
pass