In short, you cannot patch the builtins func hasattrpatch('builtins.hasattr', return_value=False)原因:被mock.pyif not _is_started(self): raise RuntimeError('stop called on unstarted patcher')def _is_started(patcher): # XXXX horrible return hasattr(patcher, 'is_local')重复错误:@mock.patch('__builtin__.hasattr')def test_mock_hasattr(self, mocked_hasattr): # as long as it is set to False, it will trigger mocked_hasattr.return_value = False模拟 models.py 中的 builtins func:to mock a builtins func inside models.py:# narrow the mock [email protected]('orders.models.hasattr') 这篇关于模拟单元测试引发“停止调用未启动的修补程序";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-23 19:17