Bird
0
0

Which of the following is the correct syntax to parametrize a test function with a single parameter num having values 1, 2, and 3?

easy📝 Syntax Q3 of 15
PyTest - Parametrize
Which of the following is the correct syntax to parametrize a test function with a single parameter num having values 1, 2, and 3?
A@pytest.mark.parametrize('num', [1, 2, 3])
B@pytest.mark.parametrize(num, [1, 2, 3])
C@pytest.mark.parametrize(['num'], (1, 2, 3))
D@pytest.mark.parametrize('num', 1, 2, 3)
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct parametrize syntax for one parameter

    The parameter name must be a string, and the values must be a list or tuple.
  2. Step 2: Evaluate each option

    @pytest.mark.parametrize('num', [1, 2, 3]) correctly uses a string and a list. @pytest.mark.parametrize(num, [1, 2, 3]) misses quotes around the parameter name. @pytest.mark.parametrize(['num'], (1, 2, 3)) uses a list for names but tuple for values incorrectly. @pytest.mark.parametrize('num', 1, 2, 3) passes multiple arguments instead of a list.
  3. Final Answer:

    @pytest.mark.parametrize('num', [1, 2, 3]) -> Option A
  4. Quick Check:

    Parametrize single param = string + list [OK]
Quick Trick: Always quote parameter names as strings [OK]
Common Mistakes:
MISTAKES
  • Not quoting parameter names
  • Passing multiple values without list or tuple
  • Using wrong data types for values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes