I'm looking for a way to implement a custom parametrisation logic for my tests. My code tends to use a polymorphic design and therefore it feels like the most sensible way to test all the polymorphic methods in a single test. A mock example of how I'd decorate the test currently:
@mark.parametrize(
("cls", "input", "expected"),
[
(ClsA, 0, True),
(ClsA, 1, False),
(ClsB, 0, False),
(ClsB, 1, True),
)
Within the test, I'd call the method on each class instance after instantiating with input and expect expected. It feels as though (especially with larger sets of parameterisations) that it would make more sense to "set" ClsA once for all parameterisations that use it, ClsB once for all parameterisations that use it etc. If you only had one cls arg, you could do that with:
@mark.parameterize(
"cls",
[ClsA],
)
@mark.parameterize(
("input", "output"),
[
(0, True),
(1, False),
]
)
However you can't use this syntax with multiple cls arguments as it would create the product of the different decorators, lacking a way to assign certain parameters in one decorator to only be used with certain parameters in another. Is there a way to do what I'm trying to achieve? Otherwise, I have to write out the same argument repetitively which feels WET.