Recall & Review
beginner
What does the 'function' scope mean in pytest fixtures?
The fixture is created and destroyed for each test function that uses it. It runs fresh for every test.
Click to reveal answer
beginner
Explain the 'class' scope for pytest fixtures.
The fixture is created once per test class and shared among all test methods in that class.Click to reveal answer
intermediate
What happens when a fixture has 'module' scope?
The fixture is created once per module (file) and shared by all tests in that module.
Click to reveal answer
intermediate
Describe the 'session' scope in pytest fixtures.
The fixture is created once for the entire test session and shared by all tests across all modules.
Click to reveal answer
intermediate
Why would you use a 'session' scoped fixture instead of a 'function' scoped one?
To save time by setting up expensive resources only once for all tests, like a database connection.
Click to reveal answer
Which pytest fixture scope creates a new fixture instance for each test function?
✗ Incorrect
The 'function' scope means the fixture is set up and torn down for every test function.
If you want a fixture to be shared by all tests in a single Python file, which scope should you use?
✗ Incorrect
The 'module' scope shares the fixture across all tests in the same file.
What is the scope that shares a fixture across all test classes and functions in the entire test run?
✗ Incorrect
The 'session' scope creates the fixture once for the whole test session.
Which scope would be best for a fixture that sets up a database connection used by many tests?
✗ Incorrect
Using 'session' scope avoids reconnecting to the database for every test, saving time.
A fixture with 'class' scope is created how many times per test class?
✗ Incorrect
The 'class' scope means the fixture is created once for each test class.
Describe the differences between the four pytest fixture scopes: function, class, module, and session.
Think about how often the fixture is created and shared.
You got /4 concepts.
Explain a real-life scenario where using a 'session' scoped fixture is better than a 'function' scoped fixture.
Imagine setting up something costly once instead of many times.
You got /3 concepts.