Bird
0
0

Consider the following pytest code:

medium📝 Predict Output Q4 of 15
PyTest - Parametrize
Consider the following pytest code:
@pytest.mark.parametrize('x', [10, 20])
@pytest.mark.parametrize('y', [1, 2, 3])
def test_multiply(x, y):
assert x * y > 0

How many test cases will pytest execute?
A5
B2
C3
D6
Step-by-Step Solution
Solution:
  1. Step 1: Count values for each parameter

    Parameter x has 2 values: 10, 20.
    Parameter y has 3 values: 1, 2, 3.
  2. Step 2: Calculate total test cases

    Total tests = 2 (x) * 3 (y) = 6.
  3. Final Answer:

    6 -> Option D
  4. Quick Check:

    Multiply parameter value counts [OK]
Quick Trick: Multiply counts of parameter values for total tests [OK]
Common Mistakes:
MISTAKES
  • Adding counts instead of multiplying
  • Confusing number of decorators with test count
  • Ignoring one parameter's values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes