我想运行从另一个类继承的所有测试方法。有办法吗?例如,对于下面的代码,我希望pytest
测试从Test
继承的TestTwo
和{
class Test:
def __init__(self, n):
self.n = n
def test_even(self):
assert self.n % 2 == 0
def test_not_big(self):
assert self.n < 100
class TestTwo(Test):
def __init__(self):
super(TestTwo, self).__init__(2)
class TestTwelve(Test):
def __init__(self):
super(TestTwelve, self).__init__(12)
但是,pytest
抱怨存在一个__init__
构造函数。我想要个办法来避开这个。在
总体目标是使我的测试更加模块化,这样我就可以在多个类上测试类似的问题。在
重用测试方法的正确用法是使用Fixtures。这是一个related question和一个example solution。在
感谢@hoefling在评论中指出
__init__
不利于测试。在相关问题 更多 >
编程相关推荐