Bird
0
0

Which of the following is the correct syntax to patch the function 'fetch_data' in module 'external.api' using unittest.mock?

easy📝 Syntax Q3 of 15
Django - Testing Django Applications
Which of the following is the correct syntax to patch the function 'fetch_data' in module 'external.api' using unittest.mock?
A@patch('external.api.fetch_data')
B@patch('fetch_data.external.api')
C@patch('external.fetch_data.api')
D@patch('api.external.fetch_data')
Step-by-Step Solution
Solution:
  1. Step 1: Understand patch target format

    Patch requires the full import path as a string: 'module.function'.
  2. Step 2: Match the correct module and function order

    The correct order is 'external.api.fetch_data' for the function fetch_data inside external.api module.
  3. Final Answer:

    @patch('external.api.fetch_data') -> Option A
  4. Quick Check:

    Patch syntax = '@patch("module.function")' [OK]
Quick Trick: Patch uses full import path: module.function [OK]
Common Mistakes:
MISTAKES
  • Reversing module and function names
  • Using dot order incorrectly
  • Missing quotes around patch target

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes