Bird
0
0

Which of the following is a correct way to parametrize a test using an indirect fixture named db?

easy🧠 Conceptual Q2 of 15
PyTest - Parametrize
Which of the following is a correct way to parametrize a test using an indirect fixture named db?
A@pytest.mark.parametrize('db', [1, 2], indirect='yes')
B@pytest.mark.parametrize('db', [1, 2], indirect=True)
C@pytest.mark.parametrize('db', [1, 2], indirect=False)
D@pytest.mark.parametrize('db', [1, 2])
Step-by-Step Solution
Solution:
  1. Step 1: Recall the syntax for indirect parametrization

    The correct syntax uses indirect=True to tell pytest to treat the parameter as a fixture input.
  2. Step 2: Check each option

    @pytest.mark.parametrize('db', [1, 2], indirect=True) correctly uses indirect=True. @pytest.mark.parametrize('db', [1, 2]) lacks indirect, so parameters go directly to the test. @pytest.mark.parametrize('db', [1, 2], indirect=False) uses indirect=False, which disables indirect behavior. @pytest.mark.parametrize('db', [1, 2], indirect='yes') uses an invalid string value.
  3. Final Answer:

    @pytest.mark.parametrize('db', [1, 2], indirect=True) -> Option B
  4. Quick Check:

    Correct syntax = indirect=True [OK]
Quick Trick: Use indirect=True exactly as a boolean, not string [OK]
Common Mistakes:
MISTAKES
  • Omitting indirect=True when needed
  • Using indirect='yes' instead of True
  • Setting indirect=False by mistake

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes