0
0
PyTesttesting~10 mins

Parametrized fixtures in PyTest - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test uses a parametrized fixture in pytest to run the same test with multiple input values. It verifies that the input number is even.

Test Code - pytest
PyTest
import pytest

@pytest.fixture(params=[2, 4, 6])
def even_number(request):
    return request.param

def test_is_even(even_number):
    assert even_number % 2 == 0, f"{even_number} is not even"
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startspytest test runner initialized-PASS
2pytest collects test_is_even and sees it uses fixture even_number with params [2,4,6]Test collection complete with 3 test cases generated-PASS
3pytest runs test_is_even with even_number=2Test function receives even_number=2assert 2 % 2 == 0PASS
4pytest runs test_is_even with even_number=4Test function receives even_number=4assert 4 % 2 == 0PASS
5pytest runs test_is_even with even_number=6Test function receives even_number=6assert 6 % 2 == 0PASS
6All parametrized tests passedTest report shows 3 passed tests-PASS
Failure Scenario
Failing Condition: One of the parametrized values is not even, e.g., 3
Execution Trace Quiz - 3 Questions
Test your understanding
How many times does the test_is_even run with the given fixture?
A2 times, skipping the last parameter
B3 times, once for each parameter
C1 time only
D4 times, including an extra default run
Key Result
Parametrized fixtures let you run the same test multiple times with different inputs, improving test coverage with less code.