from flask import Flask app = Flask(__name__) @app.route('/') def home(): return 'Hello, world!', 500
Returning status code 500 means Internal Server Error. Clients see this as a failure and may show an error message. The server does not crash; it just sends this status.
from flask import Flask app = Flask(__name__) @app.route('/greet') def greet(): return 'Hi there!' with app.test_client() as client: response = client.get('/greet') print(response.data.decode())
The test client returns response.data as bytes. Using decode() converts it to a string, so 'Hi there!' is printed.
import pytest from flask import Flask app = Flask(__name__) @pytest.fixture def client(): with app.test_client() as client: yield client def test_home(client): response = client.get('/') assert response.status_code == 200
Option D is missing a colon after the function definition, causing a syntax error. Option D has an assignment in assert, which is a syntax error too, but only one option should be correct. Option D is the first syntax error encountered.
from flask import Flask app = Flask(__name__) @app.route('/hello') def hello(): return 'Hello!' with app.test_client() as client: response = client.get('/wrong') assert response.status_code == 200
Requesting '/wrong' returns 404 Not Found. The assertion expects 200, so the test fails correctly.
Automated tests catch bugs early and verify that code changes do not break existing features. They do not affect runtime speed or server capacity directly.