因此,在我的项目中,我有一个长的(~1000行)TestCase模块,只有一个TestCase。
我想把它分成3-4个独立的TestCase模块(单独的文件)。
但是,如何使通用的 setUp 为所有模块共享固定设备?
用进口装置吗?
我在我的长模块中使用setUpClass,只有一个TestCase。
请给我建议。
发布于 2022-10-06 09:43:48
你能做的就是定义一个父类。
class CommonTestCase(unittest.TestCase):
def setUpClass(self):
# Do setup or anything else here然后,在其他文件或情况下,您可以使用继承从父类CommonTestCase使用相同的设置步骤。
from my_package import CommonTestCase
class MyTestCaseA(CommonTestCase):
def test_this(self):
# Test implementation
class MyTestCaseB(CommonTestCase):
def test_that(self):
# Test implementationhttps://stackoverflow.com/questions/73970588
复制相似问题