Bird
0
0

Given this Flask test code:

medium📝 component behavior Q13 of 15
Flask - Testing Flask Applications
Given this Flask test code:
with app.test_client() as client:
    response = client.get('/hello')
    print(response.status_code)
    print(response.data.decode())

If the '/hello' route returns 'Hello, World!' with status 200, what will be printed?
A200 Hello, World!
B404 Not Found
C500 Internal Server Error
D200 b'Hello, World!'
Step-by-Step Solution
Solution:
  1. Step 1: Understand the route response

    The route '/hello' returns the string 'Hello, World!' with HTTP status 200.
  2. Step 2: Analyze the test output

    The response.status_code will be 200. The response.data is bytes, so decoding it with decode() converts it to the string 'Hello, World!'.
  3. Final Answer:

    200 Hello, World! -> Option A
  4. Quick Check:

    Status 200 and decoded response text [OK]
Quick Trick: Decode response.data to get string content [OK]
Common Mistakes:
MISTAKES
  • Not decoding response.data (shows bytes)
  • Expecting 404 or 500 status codes incorrectly
  • Confusing status_code with response content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes