python
module_error
ai_generated
true
AttributeError: <module 'module1' from '/path/module1.py'> does not have the attribute 'func'
ID: python/unittest-mock-patch-error
80%Fix Rate
87%Confidence
0Evidence
2024-03-03First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.12 | active | — | — | — |
Root Cause
使用 unittest.mock.patch 时,目标属性不存在或路径错误
generic中文
使用 unittest.mock.patch 时,目标属性不存在或路径错误
Workarounds
-
90% success
@patch('module1.func', return_value=42) -
70% success
@patch('module1.func', create=True)
Dead Ends
Common approaches that don't work:
-
50% fail
属性可能确实存在但路径错误
-
40% fail
如果目标错误,同样会失败