Recall & Review
beginner
What is a lazy fixture in pytest?
A lazy fixture is a fixture that is not executed immediately but only when it is actually used in a test. It helps to delay setup until necessary, saving time and resources.
Click to reveal answer
beginner
How do you declare a lazy fixture in pytest?
You declare a lazy fixture by using the
@pytest.fixture decorator with scope and optionally autouse=False. The fixture code runs only when a test requests it.Click to reveal answer
intermediate
Why use lazy fixtures instead of eager fixtures?
Lazy fixtures run only when needed, which saves test execution time and avoids unnecessary setup. Eager fixtures run before every test regardless of need, which can slow tests down.
Click to reveal answer
beginner
What happens if a lazy fixture is not used in any test?
If a lazy fixture is not used by any test, it will not run at all. This means no setup or teardown code inside it will execute, saving resources.
Click to reveal answer
intermediate
Can lazy fixtures depend on other fixtures in pytest?
Yes, lazy fixtures can depend on other fixtures. The dependent fixtures will also be lazy and run only when needed by the test.
Click to reveal answer
What triggers a lazy fixture to run in pytest?
✗ Incorrect
Lazy fixtures run only when a test function includes them as parameters.
Which decorator is used to create a lazy fixture in pytest?
✗ Incorrect
The @pytest.fixture decorator creates fixtures, which are lazy by default unless autouse=True.
If a fixture is marked with autouse=True, is it lazy?
✗ Incorrect
Fixtures with autouse=True run automatically before each test, so they are not lazy.
What is a benefit of using lazy fixtures?
✗ Incorrect
Lazy fixtures save time by running only when a test actually uses them.
Can a lazy fixture depend on another fixture?
✗ Incorrect
Fixtures can depend on other fixtures, and those dependencies are lazy too.
Explain what lazy fixtures are in pytest and why they are useful.
Think about when the fixture code runs during testing.
You got /4 concepts.
Describe how fixture dependencies work with lazy fixtures in pytest.
Consider how pytest manages fixture calls.
You got /4 concepts.