Bird
0
0

Which @pytest.mark.parametrize setup with a single decorator correctly tests all combinations of a from [1, 2] and b from [3, 4] respectively?

hard🚀 Application Q15 of 15
PyTest - Parametrize
You want to test a function is_even_sum(a, b) that returns True if the sum of a and b is even. Which @pytest.mark.parametrize setup with a single decorator correctly tests all combinations of a from [1, 2] and b from [3, 4] respectively?
A@pytest.mark.parametrize('a', [1, 2]) @pytest.mark.parametrize('b', [3, 4])
B@pytest.mark.parametrize('a, b', [(1, 2), (3, 4)])
C@pytest.mark.parametrize('a, b', [(1, 3), (1, 4), (2, 3), (2, 4)])
D@pytest.mark.parametrize('a, b', [(1, 3), (2, 4)])
Step-by-Step Solution
Solution:
  1. Step 1: Understand the need to test all combinations

    We want to test every pair from a=[1,2] and b=[3,4], so all 4 pairs must be covered.
  2. Step 2: Recognize the benefit of multiple parameters

    @pytest.mark.parametrize('a, b', [(1, 3), (1, 4), (2, 3), (2, 4)]) lists all pairs explicitly: (1,3), (1,4), (2,3), (2,4).
  3. Final Answer:

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

    All pairs listed explicitly [OK]
Quick Trick: List all pairs explicitly for full coverage [OK]
Common Mistakes:
MISTAKES
  • Missing some pairs in the list
  • Using separate decorators without knowing cartesian product effect
  • Confusing parameter order or values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes