Bird
0
0

Given the code below, what will be printed when running the test?

medium📝 Predict Output Q13 of 15
PyTest - Parametrize
Given the code below, what will be printed when running the test?
import pytest

@pytest.fixture
def data(request):
    return request.param * 2

@pytest.mark.parametrize('data', [3, 5], indirect=True)
def test_double(data):
    print(data)
A6 and 10
B3 and 5
CNone and None
DError: request.param not found
Step-by-Step Solution
Solution:
  1. Step 1: Understand fixture with request.param

    The fixture data returns request.param * 2, so it doubles the parameter.
  2. Step 2: Parametrize with indirect=True

    Parameters 3 and 5 are passed to the fixture, so the test receives 6 and 10.
  3. Final Answer:

    6 and 10 -> Option A
  4. Quick Check:

    Fixture doubles param: 3*2=6, 5*2=10 [OK]
Quick Trick: Indirect param goes to fixture; fixture doubles it [OK]
Common Mistakes:
MISTAKES
  • Thinking parameters go directly to test, so expecting 3 and 5
  • Assuming request.param is unavailable causing error
  • Confusing fixture return with test parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes