[英]Pytest: Run all tests in superclass
我想运行从另一个类继承的所有测试方法。 有办法吗? 例如,对于以下代码,我希望pytest
测试从Test
继承的TestTwo
和TestTwelve
所有测试方法。
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__
构造函数。 我想要一种避免这种情况的方法。
总体目标是使测试更具模块化,以便我可以在多个类上测试类似的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.