Bird
0
0

Which of the following shows the correct way to add IDs to a pytest parametrize decorator?

easy📝 Syntax Q3 of 15
PyTest - Parametrize
Which of the following shows the correct way to add IDs to a pytest parametrize decorator?
A@pytest.mark.parametrize('x', [1, 2], id=['one', 'two'])
B@pytest.mark.parametrize('x', [1, 2], ids=['one', 'two'])
C@pytest.mark.parametrize('x', [1, 2], ids='one,two')
D@pytest.mark.parametrize('x', [1, 2], ids={'one', 'two'})
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct parameter name

    The correct keyword is ids, not id.
  2. Step 2: Correct data type for ids

    ids expects a list or iterable of strings, not a single string or a set.
  3. Step 3: Verify syntax

    @pytest.mark.parametrize('x', [1, 2], ids=['one', 'two']) uses a list of strings, which is the correct syntax.
  4. Final Answer:

    @pytest.mark.parametrize('x', [1, 2], ids=['one', 'two']) -> Option B
  5. Quick Check:

    ids must be a list of strings [OK]
Quick Trick: Use ids=['name1', 'name2'] for correct syntax [OK]
Common Mistakes:
MISTAKES
  • Using 'id' instead of 'ids'
  • Passing a single string instead of list
  • Using a set instead of list

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes