Bird
0
0

Identify the error in this pytest code using multiple parameters:

medium📝 Debug Q14 of 15
PyTest - Parametrize
Identify the error in this pytest code using multiple parameters:
import pytest

@pytest.mark.parametrize('a, b', [1, 2, 3])
def test_multiply(a, b):
    assert a * b > 0
AThe test function must return a value
BThe parameter names should be a list, not a string
CThe assertion syntax is incorrect
DThe parameter values should be tuples, not integers
Step-by-Step Solution
Solution:
  1. Step 1: Check the parameter values format

    Values must be a list of tuples matching parameters (a, b), but here it's a list of integers.
  2. Step 2: Understand why this causes error

    Pytest tries to unpack each integer into two variables, causing a TypeError.
  3. Final Answer:

    The parameter values should be tuples, not integers -> Option D
  4. Quick Check:

    Values must match parameter count [OK]
Quick Trick: Use tuples for multiple parameters values [OK]
Common Mistakes:
MISTAKES
  • Passing a flat list instead of list of tuples
  • Thinking parameter names must be a list
  • Expecting test function to return a value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes