Bird
0
0

Which of the following is the correct way to apply two @pytest.mark.parametrize decorators for parameters m and n?

easy📝 Syntax Q3 of 15
PyTest - Parametrize
Which of the following is the correct way to apply two @pytest.mark.parametrize decorators for parameters m and n?
A@pytest.mark.parametrize('m', [1, 2]) @pytest.mark.parametrize('n', [3, 4]) def test_func(m, n): pass
B@pytest.mark.parametrize('m, n', [(1, 3), (2, 4)]) def test_func(m, n): pass
C@pytest.mark.parametrize('m', [1, 2], 'n', [3, 4]) def test_func(m, n): pass
D@pytest.mark.parametrize(['m', 'n'], [1, 2, 3, 4]) def test_func(m, n): pass
Step-by-Step Solution
Solution:
  1. Step 1: Syntax for multiple decorators

    Each @pytest.mark.parametrize decorator takes a parameter name and a list of values.
  2. Step 2: Correct usage

    Applying two decorators separately for m and n is done as in @pytest.mark.parametrize('m', [1, 2]) @pytest.mark.parametrize('n', [3, 4]) def test_func(m, n): pass, but combining parameters in one decorator as in @pytest.mark.parametrize('m, n', [(1, 3), (2, 4)]) def test_func(m, n): pass is also correct and often preferred.
  3. Final Answer:

    @pytest.mark.parametrize('m, n', [(1, 3), (2, 4)]) def test_func(m, n): pass is the correct syntax for combining parameters in one decorator.
  4. Quick Check:

    Single decorator with multiple parameters [OK]
Quick Trick: Use single decorator with multiple parameters for combined values [OK]
Common Mistakes:
MISTAKES
  • Trying to pass multiple parameters in one decorator incorrectly
  • Using wrong argument format
  • Passing parameters as a single list instead of tuples

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes