Bird
0
0

Which of the following is the correct way to parametrize a test function with two parameters x and y in pytest?

easy🧠 Conceptual Q2 of 15
PyTest - Parametrize
Which of the following is the correct way to parametrize a test function with two parameters x and y in pytest?
A@pytest.mark.parametrize(('x', 'y'), [(1, 2), (3, 4))
B@pytest.mark.parametrize('x, y', [(1, 2), (3, 4)])
C@pytest.mark.parametrize(['x', 'y'], [(1, 2), (3, 4))
D@pytest.mark.parametrize('x y', [(1, 2), (3, 4)])
Step-by-Step Solution
Solution:
  1. Step 1: Recall pytest parametrize syntax

    The parameter names are passed as a single string separated by commas.
  2. Step 2: Check each option

    @pytest.mark.parametrize('x, y', [(1, 2), (3, 4)]) correctly uses a string with comma-separated parameter names and a list of tuples for values.
  3. Final Answer:

    @pytest.mark.parametrize('x, y', [(1, 2), (3, 4)]) -> Option B
  4. Quick Check:

    Param names as string with commas = correct syntax [OK]
Quick Trick: Use string with commas for multiple params [OK]
Common Mistakes:
MISTAKES
  • Using tuple or list instead of string for param names
  • Missing commas between param names
  • Using space instead of comma between param names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes