wolever / parameterized

Parameterized testing with any Python test framework
Other
833 stars 105 forks source link

Is possible to combine @parameterized.expand and @parameterized_class? #132

Open wilsonjefferson opened 2 years ago

wilsonjefferson commented 2 years ago

Hi all!

I'm implementing a parameterized unit testing class. I would like to initialize an instance of the class under test with different set of parameters (so I use @parameterized_class), and the same time I would like to run a test-method of the test class with different set of parameters BUT I would like to use a certain intialization of the instance of the class, I will consider a subset of the possible set of parameters for the test-method. Let's make an example:

class A:
    def __init__(self, value1):
       self.var = value1

    def less_than(self, value2):
       return self.var < value2
import unittest
from parameterized import parameterized, parameterized_class

@parameterized_class(('init_value'), [a1, b1, c1])
class TestA(unittest.TestCase):
     def setUp(self):
          self.instance = A(self.init_value)

    @parameterized.expand([
          (a2, True),
          (b2, False),
          (c2, True)  
     ])
     def test_less_than(self, test_value2, expected):
          self.AssertEqual(self.instance.less_than(test_value2), expected)

What I would like to see is the followings:

So, as you can see we are NOT testing, for each parameterized initialization, the test_less_than with all the possible set of parameters, but just some of them. In other words: both initializations run the same test_less_than function but with different sets of parameters.

I hope that I could explain my issue in a clear way, thank you in advance for your help!

P.s. if it is not possible, could anyway provide me an alternative way? :)

cielong commented 1 year ago

+1 Wonder if you have figure out any ways to achieve this?

ikus060 commented 1 month ago

Same here, I wish to combine parameterized_class and parameterized.expend

pisi commented 1 month ago

Same here..

wilsonjefferson commented 1 month ago

Hello, Unfortunately I did not manage to combine parameterized_class and parameterized.expend at that time and I did not try it again. It would be amazing if this feature will be included in the package.