Bird
0
0

You want to run tests that reset the database before each test. Which approach is best?

hard📝 Conceptual Q8 of 15
Flask - Testing Flask Applications
You want to run tests that reset the database before each test. Which approach is best?
ARun tests without database cleanup
BManually delete rows in each test
CUse setup and teardown methods to create and drop all tables
DUse a single global database for all tests
Step-by-Step Solution
Solution:
  1. Step 1: Understand test isolation needs

    Resetting the database ensures tests do not affect each other.
  2. Step 2: Use setup/teardown for clean DB state

    Creating and dropping tables before/after each test is the cleanest approach.
  3. Final Answer:

    Use setup and teardown methods to create and drop all tables -> Option C
  4. Quick Check:

    DB reset per test = setup/teardown methods [OK]
Quick Trick: Automate DB reset with setup/teardown in tests [OK]
Common Mistakes:
MISTAKES
  • Manually deleting rows
  • Skipping cleanup
  • Sharing one DB globally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes