Bird
0
0

What is wrong with this test code snippet?

medium📝 Debug Q14 of 15
Flask - Testing Flask Applications
What is wrong with this test code snippet?
def tearDown(self):
    db.session.remove()
    db.drop_all()
AMissing call to create_all() in tearDown
BtearDown should not remove session
Cdrop_all() should be in setUp, not tearDown
DNo call to rollback() before drop_all()
Step-by-Step Solution
Solution:
  1. Step 1: Understand tearDown purpose

    tearDown cleans up after tests by removing session and dropping tables.
  2. Step 2: Identify missing rollback before drop_all()

    Without rollback, pending changes may not be discarded, potentially causing errors or inconsistent state.
  3. Final Answer:

    No call to rollback() before drop_all() -> Option D
  4. Quick Check:

    Rollback before drop_all to discard changes [OK]
Quick Trick: Always rollback before dropping tables in tearDown [OK]
Common Mistakes:
MISTAKES
  • Thinking create_all belongs in tearDown
  • Believing session removal is wrong in tearDown
  • Ignoring rollback before drop_all

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes