Bird
0
0

Why does pytest run all combinations of parameters when multiple @pytest.mark.parametrize decorators are stacked on a test function?

hard🧠 Conceptual Q10 of 15
PyTest - Parametrize
Why does pytest run all combinations of parameters when multiple @pytest.mark.parametrize decorators are stacked on a test function?
ABecause pytest runs only the first decorator's parameters
BBecause pytest merges parameters into a single list
CBecause pytest creates a Cartesian product of all parameter sets
DBecause pytest ignores all but the last decorator
Step-by-Step Solution
Solution:
  1. Step 1: Understand stacking behavior

    Stacked parametrize decorators cause pytest to combine parameters in all possible ways.
  2. Step 2: Identify the combination method

    This combination is a Cartesian product, meaning every value from one set pairs with every value from the other.
  3. Final Answer:

    Because pytest creates a Cartesian product of all parameter sets -> Option C
  4. Quick Check:

    Stacked parametrize = Cartesian product [OK]
Quick Trick: Stacked parametrize runs Cartesian product of params [OK]
Common Mistakes:
MISTAKES
  • Thinking only first decorator runs
  • Assuming parameters merge into one list
  • Believing last decorator overrides others

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes