Recall & Review
beginner
What is a shared resource in testing?
A shared resource is something used by multiple tests, like a database or a file, which can cause conflicts if not managed properly.
Click to reveal answer
beginner
Why should tests avoid modifying shared resources directly?
Because changes can affect other tests, causing unpredictable failures and making tests unreliable.
Click to reveal answer
intermediate
How does pytest's fixture scope help in handling shared resources?
Fixture scopes like 'module' or 'session' allow setup and teardown of shared resources once for many tests, saving time and avoiding conflicts.
Click to reveal answer
intermediate
What is the purpose of the 'autouse' parameter in pytest fixtures?
It makes a fixture run automatically for tests without needing to be explicitly requested, useful for setting up shared resources.
Click to reveal answer
advanced
Explain how to safely handle a shared database connection in pytest tests.
Use a fixture with appropriate scope to create the connection once, and ensure tests clean up or reset data to avoid interference.
Click to reveal answer
What pytest fixture scope runs once per test session?
✗ Incorrect
The 'session' scope runs the fixture once for the entire test session, ideal for shared resources.
Why use fixtures to handle shared resources in pytest?
✗ Incorrect
Fixtures help reuse setup and teardown code, managing shared resources safely and efficiently.
What happens if tests modify shared resources without isolation?
✗ Incorrect
Modifying shared resources without isolation can cause unpredictable test failures.
Which pytest fixture parameter makes it run automatically for tests?
✗ Incorrect
'autouse=True' makes the fixture run automatically without explicit request.
How can you ensure tests do not interfere when sharing a resource?
✗ Incorrect
Resetting or cleaning shared resources between tests prevents interference and keeps tests reliable.
Describe how pytest fixtures help manage shared resources in tests.
Think about how you prepare and clean up resources once for many tests.
You got /4 concepts.
Explain why it is important to isolate tests when they use shared resources.
Imagine two friends sharing a toy without rules.
You got /4 concepts.