Bird
0
0

Why is it important to patch external services at the location where they are used rather than where they are defined?

hard📝 Conceptual Q10 of 15
Django - Testing Django Applications
Why is it important to patch external services at the location where they are used rather than where they are defined?
ABecause patch replaces the reference in the importing module, not the original module
BBecause patch only works on functions defined in the same file
CBecause patch automatically imports the module for you
DBecause patch changes the original module globally
Step-by-Step Solution
Solution:
  1. Step 1: Understand how patch works on references

    Patch replaces the reference to the object in the module where it is used, not the original definition.
  2. Step 2: Explain why patching usage location matters

    If you patch the original module, the importing module still uses its own reference, so patching there is necessary.
  3. Final Answer:

    Because patch replaces the reference in the importing module, not the original module -> Option A
  4. Quick Check:

    Patch target = usage location reference [OK]
Quick Trick: Patch where function is imported, not defined [OK]
Common Mistakes:
MISTAKES
  • Thinking patch changes original module globally
  • Assuming patch imports modules automatically
  • Believing patch only works in same file

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes