相关:Passing arguments to instantiate object in Pytest
我有MyClass1和2,它们被MyClass3占用了。像这样:
class MyClass1:
def __init__(self, a):
self.a = a
class MyClass2:
def __init__(self, b):
self.b = b
class MyClass3:
def __init__(self, obj1, obj2):
self.obj1 = obj1
self.obj2 = obj2
def joint_operation(self):
return self.obj1.a + self.obj2.b
我希望测试以下设置的迭代:
my_obj1 = MyClass1("a")
my_obj2 = MyClass2("b")
my_obj3 = MyClass3(my_obj1, my_obj2)
assert my_obj3.joint_operation == my_obj1.a + my_obj2.b
大概以某种方式扩展了这种模式:
@pytest.mark.parametrize("test, expected", TEST_CASES, indirect=["test"])