Bird
0
0

Why does this test client code raise an error?

medium📝 Debug Q7 of 15
Flask - Testing Flask Applications
Why does this test client code raise an error?
with app.test_client() as client:
    response = client.get('/missing_route')

Assuming no route is defined for /missing_route.
ARaises RuntimeError due to missing route
BRaises KeyError because route is missing
CNo error; response status will be 404
DRaises AttributeError on client.get()
Step-by-Step Solution
Solution:
  1. Step 1: Understand test client behavior on missing routes

    When a route is missing, Flask returns a 404 response but does not raise an error.
  2. Step 2: Confirm no exceptions raised

    Calling client.get() on a missing route returns a response with status 404, no exceptions.
  3. Final Answer:

    No error; response status will be 404 -> Option C
  4. Quick Check:

    Missing route returns 404 response, no error [OK]
Quick Trick: Missing routes return 404, not exceptions in test client [OK]
Common Mistakes:
MISTAKES
  • Expecting exceptions on missing routes
  • Confusing 404 with errors
  • Assuming client.get() fails if route missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes