jeudi 17 septembre 2020

What would be the best possible way to support multiple boolean combinations for a test in pytest?

So basically, what I am trying to do is, to generate all possible combinations of three boolean flags and later on do some operations on the basis of those combinations. Is there a way, I can do this using parameterization in pytest?

For example, my code could look something like this:

@pytest.mark.parametrize("is_flag_1,is_flag_2,is_flag_3", [(True, False), (True, False), (True, False)])
def test_something(self, is_flag_1, is_flag_2, is_flag_3):
        print(is_flag_1, is_flag_2, is_flag_3)

And this can then generate 8 possible combinations like:

  1. False, False, False
  2. False, False, True
  3. False, True, False so on and so forth till True, True, True

So instead of writing 8 different test cases, I want to do this through single test, leveraging pytest. If there is some other way other than parameterization, even that would work.

Aucun commentaire:

Enregistrer un commentaire