QuizzesTest Fixtures & Overrides — Real Tests, Fake Infrastructure — Concept Check
intermediate
fastapi

Test Fixtures & Overrides — Real Tests, Fake Infrastructure — Concept Check

Questions on Test Fixtures & Overrides — Real Tests, Fake Infrastructure. dependency_overrides swaps get_db for a per-test SQLite/test-Postgres session and get_current_user for canned users — pytest fixtures wire it so every test starts on a clean, isolated world.

7 minutes 7 questions Pass at 70%
Time Limit
7 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

7 questions on Test Fixtures & Overrides — Real Tests, Fake Infrastructure — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A test suite using dependency_overrides is running slowly. What could be a reason?

    • AExcessive use of canned users
    • BOverlapping test sessions causing conflicts
    • CUsing Postgres-in-Docker instead of SQLite for tests
    • DIncorrect dependency injection
  2. 2.What happens if app.dependency_overrides.clear() is not called after a test?

    • AOverrides may leak and affect subsequent tests
    • BDatabase connections will remain open
    • CNo impact, as overrides reset automatically
    • DTests will fail immediately
  3. 3.Why might a test pass with SQLite but fail in production with Postgres?

    • APostgres requires more memory
    • BSQLite is faster than Postgres
    • CSQLite supports more data types
    • DSQLite does not enforce Postgres-specific constraints
  4. 4.A developer uses in-memory SQLite for all tests. What is a potential issue?

    • ATests may pass despite missing Postgres features
    • BTests will be too slow
    • CIn-memory databases cannot be used in CI
    • DSQLite requires complex setup
  5. 5.A test for authorization fails unexpectedly. What might be a cause?

    • ADatabase connection error
    • BIncorrect role fixture setup
    • CUsing SQLite instead of Postgres
    • DTestClient not initialized
  6. 6.Why is each test run inside a transaction that is rolled back?

    • ATo test transaction commit behavior
    • BTo ensure no test affects another's state
    • CTo prevent schema changes
    • DTo speed up database operations
  7. 7.What is a benefit of using pytest fixtures in test setups?

    • AThey eliminate the need for dependency injection
    • BThey provide clean, isolated test environments
    • CThey speed up test execution
    • DThey automatically generate test data