Bird
0
0

Given the code below, how many test cases will pytest run?

medium📝 Predict Output Q13 of 15
PyTest - Parametrize
Given the code below, how many test cases will pytest run?
@pytest.mark.parametrize('a', [1, 2])
@pytest.mark.parametrize('b', [3, 4, 5])
def test_sum(a, b):
    assert a + b > 0
A2
B6
C3
D5
Step-by-Step Solution
Solution:
  1. Step 1: Count values for each parameter

    Parameter 'a' has 2 values: 1, 2. Parameter 'b' has 3 values: 3, 4, 5.
  2. Step 2: Calculate total test cases

    pytest runs all combinations: 2 values for 'a' x 3 values for 'b' = 6 test cases.
  3. Final Answer:

    6 -> Option B
  4. Quick Check:

    2 x 3 = 6 test cases [OK]
Quick Trick: Multiply counts of each param list for total tests [OK]
Common Mistakes:
MISTAKES
  • Adding counts instead of multiplying
  • Counting only one decorator's values
  • Confusing number of test cases with assertion results

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes