Recall & Review
beginner
What is the purpose of a
conftest.py file in pytest?The
conftest.py file is used to define shared fixtures and hooks that can be used across multiple test files without importing them explicitly.Click to reveal answer
beginner
How do you define a fixture in
conftest.py for Selenium WebDriver?You define a function with the
@pytest.fixture decorator that initializes the WebDriver, yields it for use in tests, and then quits the driver after tests finish.Click to reveal answer
beginner
Why is it better to put Selenium WebDriver setup in
conftest.py instead of each test file?Putting WebDriver setup in
conftest.py avoids repeating code, makes tests cleaner, and ensures consistent setup and teardown across all tests.Click to reveal answer
intermediate
What does the
scope parameter in a pytest fixture control?The
scope parameter controls how often the fixture is invoked. For example, scope='function' runs before each test, scope='session' runs once per test session.Click to reveal answer
beginner
How can you use a fixture from
conftest.py in your test function?Simply add the fixture name as a parameter to your test function. Pytest will automatically find and inject the fixture from
conftest.py.Click to reveal answer
What is the main benefit of using
conftest.py for fixtures?✗ Incorrect
The
conftest.py file allows sharing fixtures across test files without explicit imports.Which decorator is used to define a fixture in pytest?
✗ Incorrect
Fixtures in pytest are defined using the
@pytest.fixture decorator.If you want a Selenium WebDriver fixture to run once per test session, which scope should you use?
✗ Incorrect
Using
scope='session' makes the fixture run once for the entire test session.How do you ensure the WebDriver quits after a test using a fixture?
✗ Incorrect
Using
yield in the fixture allows setup before yield and teardown (like driver.quit()) after yield.How do you use a fixture named
browser in your test function?✗ Incorrect
Pytest injects fixtures by matching parameter names in test functions.
Explain how to create and use a Selenium WebDriver fixture in
conftest.py.Think about setup and teardown using yield.
You got /5 concepts.
Describe the benefits of using
conftest.py for shared fixtures in Selenium testing.Consider how shared setup helps in many tests.
You got /5 concepts.