Bird
0
0

Which of the following is the correct way to patch an external function requests.get in a Flask test using unittest.mock?

easy📝 Syntax Q12 of 15
Flask - Testing Flask Applications
Which of the following is the correct way to patch an external function requests.get in a Flask test using unittest.mock?
Awith patch('requests.get') as mock_get:
Bwith patch(requests.get) as mock_get:
Cwith patch('requests->get') as mock_get:
Dwith patch('requests_get') as mock_get:
Step-by-Step Solution
Solution:
  1. Step 1: Understand patch syntax

    Patch requires the full path as a string, e.g., 'requests.get'.
  2. Step 2: Identify correct string format

    with patch('requests.get') as mock_get: uses the correct string 'requests.get'. Others use invalid syntax or missing quotes.
  3. Final Answer:

    with patch('requests.get') as mock_get: -> Option A
  4. Quick Check:

    Patch needs string path = with patch('requests.get') as mock_get: [OK]
Quick Trick: Patch uses string path like 'module.function' [OK]
Common Mistakes:
MISTAKES
  • Passing function object instead of string
  • Using wrong string format with arrows
  • Missing quotes around patch target

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes