Bird
0
0

Identify the error in this pytest test code:

medium📝 Debug Q6 of 15
Selenium Python - Test Framework Integration (pytest)
Identify the error in this pytest test code:
def setup():
    print('Setup')

def test_sample():
    print('Test running')
Asetup() must return a value
Btest_sample() must be inside a class
Csetup() should be named setup_function() for pytest to recognize it
Dsetup() should be decorated with @pytest.setup
Step-by-Step Solution
Solution:
  1. Step 1: Recall pytest setup function naming

    pytest expects setup_function() to run before each test function, not setup().
  2. Step 2: Check the code for correct setup naming

    The function is named setup(), so pytest will not call it automatically.
  3. Final Answer:

    setup() should be named setup_function() for pytest to recognize it -> Option C
  4. Quick Check:

    pytest setup function = setup_function() [OK]
Quick Trick: pytest setup function must be named setup_function() [OK]
Common Mistakes:
  • Assuming any setup name works
  • Thinking setup must be in a class
  • Expecting decorators for setup

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes