Bird
0
0

Which of the following is the correct syntax to parametrize a test with two parameters, skipping one parameter conditionally?

easy📝 Syntax Q3 of 15
PyTest - Parametrize
Which of the following is the correct syntax to parametrize a test with two parameters, skipping one parameter conditionally?
A@pytest.mark.parametrize('x,y', [(1, 2), (3, 4, skip=True)])
B@pytest.mark.parametrize('x,y', [(1, 2), pytest.param(3, 4, marks=skipif(True))])
C@pytest.mark.parametrize('x,y', [(1, 2), pytest.param(3, 4, skipif=True)])
D@pytest.mark.parametrize('x,y', [(1, 2), pytest.param(3, 4, marks=pytest.mark.skipif(True, reason='skip'))])
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct parametrize syntax

    Parameters are given as a string, and values as a list of tuples or pytest.param.
  2. Step 2: Use pytest.param with marks=pytest.mark.skipif

    To skip a parameter, use marks=pytest.mark.skipif(condition, reason).
  3. Final Answer:

    @pytest.mark.parametrize('x,y', [(1, 2), pytest.param(3, 4, marks=pytest.mark.skipif(True, reason='skip'))]) -> Option D
  4. Quick Check:

    Skip param with marks=skipif inside pytest.param [OK]
Quick Trick: Use pytest.param with marks=pytest.mark.skipif for conditional skip [OK]
Common Mistakes:
MISTAKES
  • Using skip=True instead of marks
  • Passing skipif without pytest.mark
  • Incorrect tuple structure in parametrize

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes