Recall & Review
beginner
What does the fixture scope 'function' mean in pytest?
The fixture is created and destroyed for each test function. It ensures a fresh setup for every test.
Click to reveal answer
intermediate
How does the 'session' scope affect fixture usage in parallel tests?
The fixture is created once per test session and shared across all tests, which can cause conflicts if tests run in parallel and modify shared state.
Click to reveal answer
beginner
Why is 'function' scope recommended for fixtures when running tests in parallel?
Because each test gets its own fixture instance, avoiding shared state and race conditions between parallel tests.
Click to reveal answer
intermediate
What problem can arise if a 'module' scoped fixture is used with parallel tests?
Tests running in parallel might share the same fixture instance, leading to unpredictable behavior or test failures due to shared mutable state.
Click to reveal answer
advanced
How can you safely share resources in pytest fixtures when running tests in parallel?
Use locks or external services designed for concurrency, or limit fixture scope to 'function' to avoid sharing mutable state.
Click to reveal answer
Which fixture scope creates a new fixture instance for each test function?
✗ Incorrect
The 'function' scope means the fixture is created fresh for each test function.
What is a risk of using 'session' scoped fixtures with parallel tests?
✗ Incorrect
Session scoped fixtures are shared across tests, so parallel tests might conflict if they modify shared state.
To avoid race conditions in parallel tests, which fixture scope is safest?
✗ Incorrect
Function scope ensures each test has its own fixture instance, preventing shared state issues.
If you want to share a database connection safely in parallel tests, what should you do?
✗ Incorrect
Either create fresh connections per test or use synchronization to avoid conflicts.
What pytest plugin helps run tests in parallel?
✗ Incorrect
pytest-xdist allows parallel test execution.
Explain how fixture scope affects test isolation when running tests in parallel.
Think about how sharing or isolating resources impacts test reliability.
You got /4 concepts.
Describe strategies to safely share resources in pytest fixtures during parallel test execution.
Consider how to prevent race conditions and conflicts.
You got /4 concepts.