Bird
0
0

Identify the error in the following code snippet that uses conditional parametrize:

medium📝 Debug Q14 of 15
PyTest - Parametrize
Identify the error in the following code snippet that uses conditional parametrize:
import pytest

@pytest.mark.parametrize('val', [
    pytest.param(10, marks=pytest.mark.skipif('sys.version_info < (3,8)', reason='Old Python')),
    20
])
def test_val(val):
    assert val > 0
AThe skipif condition is a string instead of a boolean expression
BMissing import of sys module
Cpytest.param cannot be used inside parametrize
DThe reason argument is missing in skipif
Step-by-Step Solution
Solution:
  1. Step 1: Check skipif condition type

    The condition is passed as a string, but skipif expects a boolean expression, not a string.
  2. Step 2: Confirm other parts

    sys module is not imported, but the main error is the string condition. pytest.param usage and reason argument are correct.
  3. Final Answer:

    The skipif condition is a string instead of a boolean expression -> Option A
  4. Quick Check:

    skipif condition must be boolean, not string [OK]
Quick Trick: skipif condition must be a boolean expression, not a string [OK]
Common Mistakes:
MISTAKES
  • Passing condition as string instead of boolean
  • Ignoring missing sys import (not main error here)
  • Misusing pytest.param outside parametrize

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes