Bird
0
0

Which of the following is the correct syntax to parametrize a test with two inputs a and b in pytest?

easy📝 Syntax Q12 of 15
PyTest - Parametrize
Which of the following is the correct syntax to parametrize a test with two inputs a and b in pytest?
A@pytest.mark.parametrize(a, b, [(1, 2), (3, 4)])
B@pytest.mark.parametrize('a,b', [(1, 2), (3, 4)])
C@pytest.mark.param('a,b', (1, 2), (3, 4))
D@pytest.parametrize('a,b', [1, 2, 3, 4])
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct decorator name and parameters

    The correct decorator is @pytest.mark.parametrize with a string of parameter names and a list of tuples for values.
  2. Step 2: Match syntax to options

    @pytest.mark.parametrize('a,b', [(1, 2), (3, 4)]) correctly uses @pytest.mark.parametrize('a,b', [(1, 2), (3, 4)]). Others have wrong names or formats.
  3. Final Answer:

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

    Correct decorator and tuple list = @pytest.mark.parametrize('a,b', [(1, 2), (3, 4)]) [OK]
Quick Trick: Use @pytest.mark.parametrize with string and list of tuples [OK]
Common Mistakes:
MISTAKES
  • Misspelling 'parametrize' as 'parametrize' or 'param'
  • Passing parameters as separate arguments instead of a string
  • Using list instead of list of tuples for multiple inputs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes