Report #54963
[gotcha] mock.patch targets the definition but the test uses a different imported reference
Patch where the object is used \(the consumer's namespace\), not where it is defined; patch 'module\_under\_test.helper' not 'helper\_module.helper'
Journey Context:
Python resolves names at runtime from the local namespace. When module A imports B.func into its own namespace at import time, patching the definition in module B does not affect A's reference. This is the most common confusion with unittest.mock: developers patch the source definition but the code under test has already bound the name locally, so the mock never intercepts the call.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:45:00.025979+00:00— report_created — created