0
0
PyTesttesting~10 mins

Single parameter in PyTest - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if a function correctly doubles a single input number. It verifies the output matches the expected doubled value.

Test Code - pytest
PyTest
import pytest

def double(x):
    return x * 2

@pytest.mark.parametrize('input_value, expected', [
    (2, 4),
    (5, 10),
    (0, 0),
    (-3, -6)
])
def test_double(input_value, expected):
    result = double(input_value)
    assert result == expected, f"Expected {expected} but got {result}"
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test startspytest test runner initialized-PASS
2pytest collects test_double with 4 parameter setsTest cases ready to run with inputs (2,4), (5,10), (0,0), (-3,-6)-PASS
3Runs test_double with input_value=2, expected=4Function double called with 2Check if double(2) == 4PASS
4Runs test_double with input_value=5, expected=10Function double called with 5Check if double(5) == 10PASS
5Runs test_double with input_value=0, expected=0Function double called with 0Check if double(0) == 0PASS
6Runs test_double with input_value=-3, expected=-6Function double called with -3Check if double(-3) == -6PASS
7All parameterized tests completedAll assertions passed-PASS
Failure Scenario
Failing Condition: The double function returns incorrect value for any input
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test_double function verify?
AThat the double function returns input squared
BThat the double function returns input plus 2
CThat the double function returns input multiplied by 2
DThat the double function returns input divided by 2
Key Result
Using parameterized tests helps check multiple input cases efficiently with one test function.