Bird
0
0

Identify the error in this pytest fixture code for a Flask app:

medium📝 Debug Q14 of 15
Flask - Testing Flask Applications
Identify the error in this pytest fixture code for a Flask app:
@pytest.fixture
def client():
    app = Flask(__name__)
    client = app.test_client()
    return client
    print('Cleanup done')
AFixture must use 'yield' instead of 'return' always
BMissing '@pytest.fixture' decorator
C'app.test_client()' is not a valid method
DThe 'print' statement after 'return' will never execute
Step-by-Step Solution
Solution:
  1. Step 1: Check code after return statement

    Code after 'return' is unreachable, so 'print' will never run.
  2. Step 2: Confirm other parts are correct

    The decorator is present, 'app.test_client()' is valid, and 'return' is allowed but limits cleanup.
  3. Final Answer:

    The 'print' statement after 'return' will never execute -> Option D
  4. Quick Check:

    Code after return is unreachable [OK]
Quick Trick: Code after return is ignored; use yield for cleanup [OK]
Common Mistakes:
MISTAKES
  • Thinking print runs after return
  • Assuming return disallows fixture
  • Confusing method names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes