Bird
0
0

Given this fixture and test, what will be the output when running pytest?

medium📝 Predict Output Q4 of 15
Flask - Testing Flask Applications
Given this fixture and test, what will be the output when running pytest?
@pytest.fixture
def client():
    app = Flask(__name__)
    return app.test_client()

def test_home(client):
    response = client.get('/')
    print(response.status_code)
ASyntaxError
B200
C500
D404
Step-by-Step Solution
Solution:
  1. Step 1: Understand Flask app without routes

    The app has no route defined for '/' so it returns 404.
  2. Step 2: Check test client GET request

    client.get('/') calls the root URL, which is missing, so status code is 404.
  3. Final Answer:

    404 -> Option D
  4. Quick Check:

    Missing route = 404 response [OK]
Quick Trick: No route means 404 status code from test client [OK]
Common Mistakes:
MISTAKES
  • Assuming default route returns 200
  • Expecting 500 error without code error
  • Thinking print causes syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes