Bird
0
0

How can you combine multiple @pytest.mark.parametrize decorators and skip that case?

hard📝 framework Q15 of 15
PyTest - Parametrize
You want to test a function with parameters color and size. Colors are ['red', 'blue'], sizes are ['S', 'M', 'L']. You want to skip tests where color is 'red' and size is 'L'. How can you combine multiple @pytest.mark.parametrize decorators and skip that case?
AUse two parametrize decorators and inside the test, add <code>pytest.skip()</code> if color is 'red' and size is 'L'.
BCombine parameters in one parametrize decorator with all pairs except ('red', 'L').
CUse one parametrize decorator for color and one for size, no skipping needed.
DUse multiple parametrize decorators and mark the test with <code>@pytest.mark.skip</code>.
Step-by-Step Solution
Solution:
  1. Step 1: Use multiple parametrize decorators for color and size

    Apply two decorators, one for colors ['red', 'blue'] and one for sizes ['S', 'M', 'L'], to get all combinations.
  2. Step 2: Skip specific combination inside the test

    Inside the test function, check if color is 'red' and size is 'L'. If yes, call pytest.skip() to skip that test case.
  3. Final Answer:

    Use two parametrize decorators and inside the test, add pytest.skip() if color is 'red' and size is 'L'. -> Option A
  4. Quick Check:

    Skip specific combos inside test with pytest.skip() [OK]
Quick Trick: Skip unwanted combos inside test using pytest.skip() [OK]
Common Mistakes:
MISTAKES
  • Trying to exclude combos in parametrize decorators directly
  • Using @pytest.mark.skip to skip all tests
  • Combining all pairs manually instead of skipping in test

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes