Report #6572
[gotcha] Mocking a function has no effect on code that already imported it
Patch the object where it is used \(the 'consumer'\), not where it is defined; patch 'module.submodule.function\_name' if the code does \`from module.submodule import function\_name\`
Journey Context:
Python's import system binds names in the importing module's namespace to the imported object. If you patch the origin module, the importing module still holds the reference to the original object. You must patch the name in the namespace where the lookup occurs at runtime. This is the 'where to patch' rule: patch where the name is used, not where the object lives.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T00:22:23.827925+00:00— report_created — created