Bird
0
0

Identify the error in this conftest.py fixture:

medium📝 Debug Q7 of 15
Selenium Python - Test Framework Integration (pytest)
Identify the error in this conftest.py fixture:
@pytest.fixture
def browser():
    driver = webdriver.Chrome()
    yield driver
    driver.quit()
    print("Driver closed")
ACode after yield runs after test, so print is unreachable
BThe fixture should return driver, not yield
Cdriver.quit() should be before yield
DMissing import for webdriver
Step-by-Step Solution
Solution:
  1. Step 1: Review fixture code

    The fixture uses webdriver.Chrome() but no import statement is shown.
  2. Step 2: Identify missing import

    Without importing webdriver from Selenium, this code will raise a NameError.
  3. Final Answer:

    Missing import for webdriver -> Option D
  4. Quick Check:

    Missing imports cause runtime errors [OK]
Quick Trick: Always import modules used in fixtures [OK]
Common Mistakes:
  • Misunderstanding yield behavior
  • Placing quit before yield
  • Ignoring missing imports

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes