Bird
0
0

Given this Flask test code snippet, what will print(response.status_code) output?

medium📝 component behavior Q4 of 15
Flask - Testing Flask Applications
Given this Flask test code snippet, what will print(response.status_code) output?
from flask import Flask
app = Flask(__name__)

@app.route('/hello')
def hello():
    return 'Hi there!', 200

with app.test_client() as client:
    response = client.get('/hello')
A200
B404
C500
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the route and response

    The route '/hello' returns 'Hi there!' with status code 200.
  2. Step 2: Understand test client request

    The test client sends a GET request to '/hello', which matches the route and returns 200.
  3. Final Answer:

    200 -> Option A
  4. Quick Check:

    Response status code = 200 [OK]
Quick Trick: Matching route returns its status code in test client response [OK]
Common Mistakes:
MISTAKES
  • Expecting 404 for existing route
  • Confusing status code with response data
  • Assuming None or error without route

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes