Test addition function with multiple input sets using combined parametrize decorators
Preconditions (2)
✅ Expected Result: The test runs 4 times with combinations (1,3), (1,4), (2,3), (2,4) and all assertions pass
import pytest @pytest.mark.parametrize('a', [1, 2]) @pytest.mark.parametrize('b', [3, 4]) def test_addition(a, b): expected = a + b assert a + b == expected
This test uses two @pytest.mark.parametrize decorators to provide values for parameters a and b. Pytest combines these to run the test for all pairs: (1,3), (1,4), (2,3), and (2,4).
The test function test_addition takes both parameters and asserts their sum equals the expected value. This confirms the addition logic works for all input combinations.
Using multiple parametrize decorators is a clean way to test combinations without writing nested loops.
Now add a third parametrize decorator for parameter 'c' with values 5 and 6 and update the test to assert a + b + c
@pytest.mark.parametrize decorators on a single test function?@pytest.mark.parametrize decorator adds a set of parameters to the test function.@pytest.mark.parametrize decorators for parameters x and y?@pytest.mark.parametrize decorators, one for each parameter. -> Option D@pytest.mark.parametrize('a', [1, 2])
@pytest.mark.parametrize('b', [3, 4, 5])
def test_sum(a, b):
assert a + b > 0
@pytest.mark.parametrize('x', [1, 2])
@pytest.mark.parametrize('y', 3, 4)
def test_func(x, y):
assert x != y
@pytest.mark.parametrize('y', 3, 4), which is invalid because values must be in a list or iterable.[3, 4]. Without brackets, it causes a syntax or runtime error.color and size. Colors are ['red', 'blue'], sizes are ['S', 'M', 'L']. You want to skip tests where color is 'red' and size is 'L'. How can you combine multiple @pytest.mark.parametrize decorators and skip that case?pytest.skip() to skip that test case.Pass the test and this pattern moves unknown