Bird
0
0

You want to test a fixture that sets up a database connection string based on parameters. Which approach correctly uses indirect parametrization to pass different connection strings to the fixture?

hard🚀 Application Q8 of 15
PyTest - Parametrize
You want to test a fixture that sets up a database connection string based on parameters. Which approach correctly uses indirect parametrization to pass different connection strings to the fixture?
AUse @pytest.mark.parametrize('db_conn', ['conn1', 'conn2'], indirect='yes') and a fixture that returns request.param
BUse @pytest.mark.parametrize('db_conn', ['conn1', 'conn2']) and a fixture that returns a fixed string
CUse @pytest.mark.parametrize('db_conn', ['conn1', 'conn2'], indirect=False) and a fixture that ignores parameters
DUse @pytest.mark.parametrize('db_conn', ['conn1', 'conn2'], indirect=True) and a fixture that returns request.param
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct indirect usage

    To pass connection strings to the fixture, use indirect=True in the parametrize decorator.
  2. Step 2: Confirm fixture accesses parameters

    The fixture should accept request and return request.param to use the passed connection strings.
  3. Final Answer:

    Use @pytest.mark.parametrize('db_conn', ['conn1', 'conn2'], indirect=True) and a fixture that returns request.param -> Option D
  4. Quick Check:

    Indirect param passes values to fixture via request.param [OK]
Quick Trick: Pass connection strings via indirect=True and request.param [OK]
Common Mistakes:
MISTAKES
  • Not using indirect=True when fixture needs params
  • Using indirect='yes' instead of True
  • Ignoring fixture parameter access

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes