Bird
0
0

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

easy📝 Syntax Q3 of 15
PyTest - Parametrize
Which of the following shows the correct way to parametrize a pytest 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', [1, 3]) @pytest.mark.parametrize('n', [2, 4])
D@pytest.mark.parametrize('m,n', 1, 2, 3, 4)
Step-by-Step Solution
Solution:
  1. Step 1: Review parametrize syntax

    The correct syntax for multiple parameters is a string of comma-separated names and a list of tuples with values.
  2. Step 2: Evaluate options

    @pytest.mark.parametrize('m,n', [(1, 2), (3, 4)]) correctly uses 'm,n' and a list of tuples. @pytest.mark.parametrize(['m', 'n'], [1, 2, 3, 4]) incorrectly uses a list of strings and a flat list. @pytest.mark.parametrize('m', [1, 3]) @pytest.mark.parametrize('n', [2, 4]) is valid syntax but uses two decorators, not a single one. @pytest.mark.parametrize('m,n', 1, 2, 3, 4) has incorrect argument format.
  3. Final Answer:

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

    Parametrize multiple args with string and list of tuples [OK]
Quick Trick: Use string of names and list of tuples for multiple params [OK]
Common Mistakes:
MISTAKES
  • Passing parameters as separate arguments instead of a list
  • Using list of strings instead of tuples for values
  • Confusing multiple decorators with single parametrize

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes