PyTest parameterize only certain permutations?

Viewed 1189

I have three fields that I am parameterizing:

@pytest.mark.parametrize("country", ['US', 'Canada', 'Mexico'])
@pytest.mark.parametrize("city", ['Chicago', 'Atlanta', 'Mexico City'])
@pytest.mark.parametrize("street", ['Washington Ave', 'Peachtree'])
def test_mytest(country, city, street):
    # ...
    # assert things

Is there a way that I can build the permutations from the top down and leave the lower levels empty for some tests? I want to get parameters like this:

Country     City        Street
US          None        None
US          Chicago     None
US          Chicago     Washington Ave
US          Chicago     Peachtree
US          Atlanta     None
US          Atlanta     Washington Ave
US          Atlanta     Peachtree
US          Mexico City None
US          Mexico City Washington Ave
US          Mexico City Peachtree

etc...

If it helps, think of this as a 3 box dependent drop down. Boxes 2 and 3 can't have a value until the preceding box has a value.

If I put a 'None' in the city or street declarations, then a None can appear when it shouldn't and generate an invalid case like this:

Country     City        Street
US          None        Peachtree

Can I use parameterize to get what I want?

1 Answers
Related