Bird
0
0

How do you correctly parametrize the test to pass these paths to the fixture using indirect parametrization, when there are other direct parameters?

hard🚀 Application Q15 of 15
PyTest - Parametrize
You want to test a fixture config that reads a file path from parameters and loads data. You have two file paths: "file1.json" and "file2.json". How do you correctly parametrize the test to pass these paths to the fixture using indirect parametrization, when there are other direct parameters?
A@pytest.mark.parametrize('config', ["file1.json", "file2.json"], indirect=['config'])
B@pytest.mark.parametrize('config', ["file1.json", "file2.json"])
C@pytest.mark.parametrize('config', ["file1.json", "file2.json"], indirect=True)
D@pytest.mark.parametrize('config', ["file1.json", "file2.json"], indirect=False)
Step-by-Step Solution
Solution:
  1. Step 1: Identify indirect parameter usage for single fixture

    When passing parameters to a fixture, use indirect=['fixture_name'] to mark that parameter indirect.
  2. Step 2: Apply to config fixture

    Since only config is indirect, use indirect=['config'] with the list of file paths.
  3. Final Answer:

    @pytest.mark.parametrize('config', ["file1.json", "file2.json"], indirect=['config']) -> Option A
  4. Quick Check:

    Use indirect=['config'] to pass params to fixture [OK]
Quick Trick: Use indirect=['fixture_name'] to pass params to fixture [OK]
Common Mistakes:
MISTAKES
  • Using indirect=True instead of list for single param
  • Not using indirect causing fixture to miss parameters
  • Setting indirect=False disables indirect passing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes