Bird
0
0

Which of the following is the correct way to declare a fixture in conftest.py using pytest?

easy📝 Syntax Q12 of 15
Selenium Python - Test Framework Integration (pytest)
Which of the following is the correct way to declare a fixture in conftest.py using pytest?
Adef browser(): yield webdriver.Chrome()
B@pytest.fixture def browser(): yield webdriver.Chrome()
Cfixture browser(): yield webdriver.Chrome()
D@fixture def browser(): return webdriver.Chrome()
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct fixture decorator usage

    pytest fixtures require the @pytest.fixture decorator above the function to mark it as a fixture.
  2. Step 2: Check syntax correctness

    @pytest.fixture def browser(): yield webdriver.Chrome() correctly uses @pytest.fixture and a generator with yield to provide the resource.
  3. Final Answer:

    @pytest.fixture\ndef browser(): yield webdriver.Chrome() -> Option B
  4. Quick Check:

    Use @pytest.fixture decorator [OK]
Quick Trick: Always prefix fixture functions with @pytest.fixture [OK]
Common Mistakes:
  • Omitting @pytest.fixture decorator
  • Using wrong decorator name like @fixture
  • Not using yield for setup/teardown

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes