Bird
0
0

Identify the error in this pytest code snippet:

medium📝 Debug Q6 of 15
PyTest - Parametrize
Identify the error in this pytest code snippet:
import pytest

@pytest.mark.parametrize('val', 5, 10, 15)
def test_greater_than_zero(val):
    assert val > 0
AThe test function must have no parameters when using parametrize.
BThe parameter name should be a list instead of a string.
CThe parameter values should be passed as a list or tuple inside square brackets.
DThe assertion operator > is invalid in pytest.
Step-by-Step Solution
Solution:
  1. Step 1: Check parametrize syntax

    The second argument to @pytest.mark.parametrize must be a list or tuple of values, e.g., [5, 10, 15].
  2. Step 2: Identify the error

    Here, values are passed as separate arguments instead of a single iterable.
  3. Final Answer:

    The parameter values should be passed as a list or tuple inside square brackets. -> Option C
  4. Quick Check:

    Are values inside a list or tuple? No [OK]
Quick Trick: Values must be in a list or tuple [OK]
Common Mistakes:
MISTAKES
  • Passing multiple values as separate arguments
  • Using list for parameter names instead of string
  • Misunderstanding assertion operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes