passing more than one argument to instantiate more than one object in Pytest

让人想犯罪 __ 提交于 2019-12-24 20:47:44

问题


Related: Passing arguments to instantiate object in Pytest

I have MyClass1 and 2 which get consumed by MyClass3. Like so:

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

I wish to test the iterations of the following setup:

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

Presumably extending this pattern somehow:

@pytest.mark.parametrize("test, expected", TEST_CASES, indirect=["test"])

来源:https://stackoverflow.com/questions/52599849/passing-more-than-one-argument-to-instantiate-more-than-one-object-in-pytest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!