Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wilsonjefferson opened this issue Oct 2, 2021 · 4 comments

Comments

@wilsonjefferson
Copy link

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:

  • The initialization of the A's instance with paramenter a1 is used with the set of sets of parameters (a2, True), (b2, False);
  • The initialization of A's instance with parameter b1 is used with the set of paramenters (b2, False);
  • The initialization of A's instance with parameter c1 is used with the set of parameters (b2, False), (c2, True).

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
Copy link

cielong commented Dec 3, 2022

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

@ikus060
Copy link

ikus060 commented Jul 15, 2024

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

@pisi
Copy link

pisi commented Jul 23, 2024

Same here..

@wilsonjefferson
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants