0

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"])
GlaceCelery
  • 921
  • 1
  • 13
  • 30
  • 1
    Add second parametrization marker for `my_fixture2`: `@pytest.mark.parametrize("my_fixture2", TEST_CASES2, indirect=True)`. – hoefling Oct 01 '18 at 22:51
  • will this multiply the tests? I would prefer to jointly define the inputs. Something like a list of specific combinations and their expected results: [MyClass1(1), MyClass2(1), result] – GlaceCelery Oct 01 '18 at 23:39
  • 1
    Then you need to explicitly explain what do you mean by _parametrize these objects separately_. Specify what test instances with what parameters you need to produce. – hoefling Oct 01 '18 at 23:51
  • I have updated the question – GlaceCelery Oct 02 '18 at 20:44

0 Answers0