parameterized test with cartesian product of arguments in pytest

前端 未结 3 547
迷失自我
迷失自我 2020-12-24 06:09

Just wondering, is there any (more) elegant way of parameterizing with the cartesian product? This is what I figured out so far:

numbers    = [1,2,3,4,5]
vow         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 06:35

    You can apply multiple parametrize arguments, in which case they will generate a product of all parameters:

    import pytest
    
    numbers = [1,2,3,4,5]
    vowels = ['a','e','i','o','u']
    consonants = ['x','y','z']
    
    
    @pytest.mark.parametrize('number', numbers)
    @pytest.mark.parametrize('vowel', vowels)
    @pytest.mark.parametrize('consonant', consonants)
    def test(number, vowel, consonant):
        pass
    

提交回复
热议问题