Bird
0
0

Identify the issue in this Flask test code:

medium📝 Debug Q6 of 15
Flask - Testing Flask Applications
Identify the issue in this Flask test code:
client = app.test_client()
response = client.get('/profile')
print(response.status)
AThe route '/profile' is invalid in Flask
BThe test client cannot send GET requests
CThe attribute 'status' does not exist; should use 'status_code'
DPrinting response is not allowed in tests
Step-by-Step Solution
Solution:
  1. Step 1: Check response attributes

    Flask response objects have status_code, not status.
  2. Step 2: Analyze options

    The attribute 'status' does not exist; should use 'status_code' correctly identifies the attribute error; others are incorrect.
  3. Final Answer:

    The attribute 'status' does not exist; should use 'status_code' -> Option C
  4. Quick Check:

    Use response.status_code, not response.status [OK]
Quick Trick: Use response.status_code to get HTTP status [OK]
Common Mistakes:
MISTAKES
  • Using response.status instead of response.status_code
  • Assuming test client can't send GET
  • Thinking printing response is disallowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes