Bird
0
0

Which of the following is the correct syntax to parameterize a test function with two parameters username and password using pytest?

easy📝 Syntax Q12 of 15
Selenium Python - Test Framework Integration (pytest)
Which of the following is the correct syntax to parameterize a test function with two parameters username and password using pytest?
A@pytest.mark.param('username', 'password', [('user1', 'pass1'), ('user2', 'pass2')])
B@pytest.parametrize(['username', 'password'], [('user1', 'pass1'), ('user2', 'pass2')])
C@pytest.mark.parametrize(('username', 'password'), ['user1', 'pass1', 'user2', 'pass2'])
D@pytest.mark.parametrize('username, password', [('user1', 'pass1'), ('user2', 'pass2')])
Step-by-Step Solution
Solution:
  1. Step 1: Recall pytest parameterize syntax

    The correct syntax uses @pytest.mark.parametrize with a string of comma-separated parameter names and a list of tuples for values.
  2. Step 2: Compare options

    @pytest.mark.parametrize('username, password', [('user1', 'pass1'), ('user2', 'pass2')]) matches the correct syntax exactly. Others have wrong decorator names or wrong argument formats.
  3. Final Answer:

    @pytest.mark.parametrize('username, password', [('user1', 'pass1'), ('user2', 'pass2')]) -> Option D
  4. Quick Check:

    Correct decorator and tuple list = @pytest.mark.parametrize('username, password', [('user1', 'pass1'), ('user2', 'pass2')]) [OK]
Quick Trick: Remember: mark.parametrize with string params and list of tuples [OK]
Common Mistakes:
  • Misspelling 'parametrize' as 'parametrize' or 'param'
  • Using list instead of tuple for parameter values
  • Passing parameters as list instead of string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes