Bird
0
0

Which of the following is the correct way to parametrize a pytest test function with parameters m and n?

easy📝 Syntax Q3 of 15
PyTest - Parametrize
Which of the following is the correct way to parametrize a pytest test function with parameters m and n?
A@pytest.mark.parametrize(['m', 'n'], [1, 2, 3, 4])
B@pytest.mark.parametrize('m,n', [(1, 2), (3, 4)])
C@pytest.mark.parametrize('m,n', [1, 2, 3, 4])
D@pytest.mark.parametrize('m', [1, 2]) @pytest.mark.parametrize('n', [3, 4])
Step-by-Step Solution
Solution:
  1. Step 1: Check param names and values

    The correct syntax requires a string of parameter names separated by commas and a list of tuples with corresponding values.
  2. Step 2: Analyze options

    @pytest.mark.parametrize('m,n', [(1, 2), (3, 4)]) correctly uses a string 'm,n' and a list of tuples [(1, 2), (3, 4)]. Options B and C incorrectly format the values. @pytest.mark.parametrize('m', [1, 2]) @pytest.mark.parametrize('n', [3, 4]) uses multiple decorators which is valid but changes the test behavior.
  3. Final Answer:

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

    Parametrize needs parameter string and list of tuples [OK]
Quick Trick: Use string of params and list of tuples [OK]
Common Mistakes:
MISTAKES
  • Passing a flat list instead of list of tuples
  • Using list of strings instead of a single string for parameters
  • Misusing multiple decorators without understanding combinations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes