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] vowels = ['a','e','i','o','u'] consonants = ['x','y','z'] cartesian = [elem for elem in itertools.product(*[numbers,vowels,consonants])] @pytest.fixture(params=cartesian) def someparams(request): return request.param def test_something(someparams): pass
At least I'd like to encapsulate numbers, vowels, consonants and cartesian in the fixture function.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With