Bird
0
0

Given the following pytest test code, what will be the output when running the test?

medium📝 Predict Output Q4 of 15
Selenium Python - Test Framework Integration (pytest)
Given the following pytest test code, what will be the output when running the test?
import pytest
from selenium import webdriver

@pytest.fixture
 def driver():
    driver = webdriver.Chrome()
    yield driver
    driver.quit()

def test_title(driver):
    driver.get('https://example.com')
    assert 'Example Domain' in driver.title
ATest passes if the page title contains 'Example Domain'
BTest fails due to missing driver initialization
CTest raises a syntax error because of indentation
DTest skips because no markers are set
Step-by-Step Solution
Solution:
  1. Step 1: Check fixture correctness

    The fixture has incorrect indentation for the driver() function definition, causing a syntax error.
  2. Step 2: Analyze test function

    Due to the syntax error in fixture, the test will not run and will raise an error.
  3. Final Answer:

    Test raises a syntax error because of indentation -> Option C
  4. Quick Check:

    Incorrect indentation causes syntax error [OK]
Quick Trick: Indentation errors cause syntax errors [OK]
Common Mistakes:
  • Misreading indentation as error
  • Assuming driver is not initialized
  • Thinking test skips without markers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes