0
0
PyTesttesting~10 mins

Combining multiple parametrize decorators in PyTest - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test uses two @pytest.mark.parametrize decorators to run a function with all combinations of two sets of inputs. It verifies the sum of two numbers equals the expected result.

Test Code - pytest
PyTest
import pytest

@pytest.mark.parametrize('a', [1, 2])
@pytest.mark.parametrize('b', [10, 20])
def test_sum(a, b):
    result = a + b
    assert result == a + b  # simple check to confirm sum calculation
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test startspytest test runner initialized-PASS
2pytest collects test_sum with parameters a=[1,2] and b=[10,20]Test cases generated for all combinations: (a=1,b=10), (a=1,b=20), (a=2,b=10), (a=2,b=20)-PASS
3Test case runs with a=1, b=10Function test_sum called with a=1, b=10Assert result == 11PASS
4Test case runs with a=1, b=20Function test_sum called with a=1, b=20Assert result == 21PASS
5Test case runs with a=2, b=10Function test_sum called with a=2, b=10Assert result == 12PASS
6Test case runs with a=2, b=20Function test_sum called with a=2, b=20Assert result == 22PASS
7All test cases completedAll combinations tested successfully-PASS
Failure Scenario
Failing Condition: Assertion fails if the sum calculation is incorrect
Execution Trace Quiz - 3 Questions
Test your understanding
How many total test cases are run with two parametrize decorators each having 2 values?
A2
B4
C1
D8
Key Result
Using multiple parametrize decorators runs tests for all combinations of parameters, helping check many input cases efficiently.