0
0
PyTesttesting~10 mins

Multiple parameters in PyTest - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks a function that adds two numbers. It uses multiple parameters to test different pairs of numbers and verifies the sum is correct.

Test Code - pytest
PyTest
import pytest

@pytest.mark.parametrize("a,b,expected", [
    (1, 2, 3),
    (5, 5, 10),
    (10, -2, 8),
    (0, 0, 0)
])
def test_addition(a, b, expected):
    result = a + b
    assert result == expected, f"Expected {expected} but got {result}"
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test startspytest test runner initialized-PASS
2Test runner reads @pytest.mark.parametrize with parameters (a,b,expected)Test cases prepared for each parameter set-PASS
3Test case 1 runs with a=1, b=2, expected=3Function adds 1 + 2Check if result == 3PASS
4Test case 2 runs with a=5, b=5, expected=10Function adds 5 + 5Check if result == 10PASS
5Test case 3 runs with a=10, b=-2, expected=8Function adds 10 + (-2)Check if result == 8PASS
6Test case 4 runs with a=0, b=0, expected=0Function adds 0 + 0Check if result == 0PASS
7All parameterized tests completeTest report generated with all passes-PASS
Failure Scenario
Failing Condition: If the function returns a wrong sum for any parameter set
Execution Trace Quiz - 3 Questions
Test your understanding
What does @pytest.mark.parametrize do in this test?
ARuns the test multiple times with different input values
BSkips the test
CRuns the test only once
DChanges the test function name
Key Result
Using multiple parameters in tests helps check many input cases easily and ensures the function works correctly for different values.