Recall & Review
beginner
What is an autouse fixture in pytest?
An autouse fixture is a pytest fixture that runs automatically for tests without needing to be explicitly requested. It helps set up or tear down test environments silently.
Click to reveal answer
beginner
How do you declare a fixture as autouse in pytest?
You add the parameter
autouse=True in the @pytest.fixture decorator. For example: @pytest.fixture(autouse=True).Click to reveal answer
intermediate
When should you use autouse fixtures?
Use autouse fixtures for setup or cleanup steps that every test needs, like resetting a database or configuring environment variables, so you don't have to add them to each test manually.
Click to reveal answer
intermediate
Can autouse fixtures accept parameters?
Yes, autouse fixtures can accept parameters like any other fixture. They can also depend on other fixtures to build complex setups.
Click to reveal answer
advanced
What is a potential downside of using autouse fixtures?
Autouse fixtures run for every test in their scope, which can slow down tests if the setup is heavy or unnecessary for some tests. It can also make tests less clear because the setup is hidden.
Click to reveal answer
How do you make a pytest fixture run automatically for all tests without explicitly requesting it?
✗ Incorrect
Adding autouse=True in the @pytest.fixture decorator makes the fixture run automatically for all tests in its scope.
What is the default scope of an autouse fixture if not specified?
✗ Incorrect
By default, fixtures (including autouse) have function scope, meaning they run before each test function.
Which of the following is a good use case for autouse fixtures?
✗ Incorrect
Autouse fixtures are ideal for setup tasks needed by all tests, like database connections.
If an autouse fixture is slow, what is a likely impact?
✗ Incorrect
Since autouse fixtures run for every test, a slow fixture will slow down the entire test suite.
Can autouse fixtures be used with scopes other than 'function'?
✗ Incorrect
Autouse fixtures can have any scope: function, class, module, or session.
Explain what autouse fixtures are and how they help in pytest testing.
Think about how some setup steps should happen for every test without writing extra code.
You got /4 concepts.
Describe a scenario where using an autouse fixture might slow down your tests and how to avoid it.
Consider what happens if a slow setup runs before every test function.
You got /4 concepts.