Complete the code to parametrize a test with two values.
import pytest @pytest.mark.parametrize('num', [1]) def test_is_positive(num): assert num > 0
The @pytest.mark.parametrize decorator expects an iterable like a list or tuple. Using a list [1, 2] correctly passes the values.
Complete the code to parametrize a test with two arguments and IDs.
import pytest @pytest.mark.parametrize( 'input,expected', [(2, 4), (3, 9)], ids=[1] ) def test_square(input, expected): assert input ** 2 == expected
The ids parameter takes a list of strings to name each test case. Using ['two', 'three'] clearly identifies the test cases.
Fix the error in the parametrize decorator by completing the IDs argument correctly.
import pytest @pytest.mark.parametrize( 'value', [10, 20, 30], ids=[1] ) def test_greater_than_five(value): assert value > 5
The ids list must have the same number of elements as the test data. Here, three values require three ID strings.
Fill both blanks to parametrize a test with multiple arguments and custom IDs.
import pytest @pytest.mark.parametrize( [1], [(1, 'a'), (2, 'b')], ids=[2] ) def test_multiple_args(num, char): assert isinstance(num, int) and isinstance(char, str)
The first blank is the string of argument names separated by commas. The second blank is a list of ID strings matching the test cases.
Fill all three blanks to parametrize a test with three arguments, test data, and custom IDs.
import pytest @pytest.mark.parametrize( [1], [2], ids=[3] ) def test_three_args(x, y, z): assert x < y < z
The first blank is the string of argument names. The second blank is the list of tuples with test data. The third blank is the list of ID strings for each test case.