我有以下 Python UnitTest:
import unittest
class SimpleTestCases(unittest.TestCase):
def setUp(self):
print "\nmessage from function: setUp"
self.createResource()
self.addCleanup(self.cleanResource)
def createResource(self):
print "\nmessage from function: createResource"
def cleanResource(self):
print "\nmessage from function: cleanResource"
def test_func1(self):
print "message from function: test_func1::start"
print "message from function: test_func1::end"
def test_func2(self):
print "message from function: test_func2::start"
self.assertTrue(False)
print "message from function: test_func2::end"
def test_func3(self):
print "message from function: test_func3::start"
print "message from function: test_func3:end"
if __name__ == "__main__":
unittest.main()
上面带有选项“-f”的代码执行后,函数按以下顺序执行
python -m unittest -fb test_cases
message from function: setUp
message from function: createResource
message from function: test_func1::start
message from function: test_func1::end
message from function: cleanResource
.
message from function: setUp
message from function: createResource
message from function: test_func2::start
F
message from function: cleanResource
======================================================================
FAIL: test_func2 (test_cases.SimpleTestCases)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_cases.py", line 23, in test_func2
self.assertTrue(False)
AssertionError: False is not true
----------------------------------------------------------------------
Ran 2 tests in 0.000s
FAILED (failures=1)
它会在第一次失败后停止执行,但会调用“addCleanup”方法。
我想避免在测试函数“test_func2”时调用“addCleanup”方法,以便创建的资源可用于调试目的。
是否有可用的命令行选项或解决方法?
千巷猫影
浮云间
相关分类