0
0
PyTesttesting~10 mins

@pytest.mark.parametrize decorator - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test uses @pytest.mark.parametrize to run the same test function with different input values. It verifies that the function correctly doubles the input number.

Test Code - pytest
PyTest
import pytest

@pytest.mark.parametrize("input_value,expected", [
    (1, 2),
    (5, 10),
    (0, 0),
    (-3, -6)
])
def test_double(input_value, expected):
    result = input_value * 2
    assert result == expected, f"Expected {expected} but got {result}"
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Test starts with parameter input_value=1 and expected=2Test environment ready, no browser involvedCheck if 1 * 2 equals 2PASS
2Test runs with parameter input_value=5 and expected=10Test environment readyCheck if 5 * 2 equals 10PASS
3Test runs with parameter input_value=0 and expected=0Test environment readyCheck if 0 * 2 equals 0PASS
4Test runs with parameter input_value=-3 and expected=-6Test environment readyCheck if -3 * 2 equals -6PASS
Failure Scenario
Failing Condition: The function returns a wrong doubled value for any input
Execution Trace Quiz - 3 Questions
Test your understanding
What does the @pytest.mark.parametrize decorator do in this test?
ASkips the test function
BRuns the test function only once
CRuns the test function multiple times with different inputs
DChanges the test function name
Key Result
Using @pytest.mark.parametrize helps test the same logic with many inputs easily, improving test coverage and saving time.