Bird
0
0

How many test cases will pytest run if you use @pytest.mark.parametrize('p', [0,1]) and @pytest.mark.parametrize('q', ['a','b']) stacked on the same test function?

hard🚀 Application Q8 of 15
PyTest - Parametrize
You want to test a function with parameters p and q where p can be 0 or 1 and q can be 'a' or 'b'. How many test cases will pytest run if you use @pytest.mark.parametrize('p', [0,1]) and @pytest.mark.parametrize('q', ['a','b']) stacked on the same test function?
A2 test cases
B3 test cases
C1 test case
D4 test cases
Step-by-Step Solution
Solution:
  1. Step 1: Understand stacking parametrize decorators

    Stacked decorators create a Cartesian product of parameters.
  2. Step 2: Calculate total test cases

    2 values for p times 2 values for q equals 4 test cases.
  3. Final Answer:

    4 test cases -> Option D
  4. Quick Check:

    Stacked parametrize = product of param counts [OK]
Quick Trick: Stacked parametrize multiplies test cases [OK]
Common Mistakes:
MISTAKES
  • Assuming tests run only for one param set
  • Adding counts instead of multiplying
  • Confusing stacking with single decorator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes