在下面的代码中
class TestSomething(unittest.TestCase):
def setUp(self):
print("setting up")
@unittest.skip("skip reason")
def test_1(self):
print("in test 1")
def test_2(self):
print("in test 2")
我只期望 test_2
来运行。但两个测试都在运行。我怀疑这是由于 setUp
函数,因为如果我删除它,那么只有 test_2
运行,如期而至。
有什么解决方法吗?
@unittest.skip(reason)
在以下情况下工作正常 setUp
方法,无法重现。
例如test_something.py
:
import unittest
class TestSomething(unittest.TestCase):
def setUp(self):
print("setting up")
@unittest.skip("skip reason")
def test_1(self):
print("in test 1")
def test_2(self):
print("in test 2")
if __name__ == '__main__':
unittest.main()
单元测试结果。
ssetting up
in test 2
.
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK (skipped=1)