我正在尝试模拟一个在其中使用 ac 扩展类的类函数,如下所示,但我得到TypeError: can't set attributes of built-in/extension type 'y.cExtensionClass'
. code.py 是遗留代码,我真的不想更改它。有什么建议吗?
代码.py:
from x.y import cExtensionClass
class CodeClass():
@staticmethod
def code_function():
cExtensionClass().cExtensionFunc()
测试.py:
import code
from x.y import cExtensionClass
class test(unittest.TestCase):
def test_code_function(self)
with patch.object(cExtensionClass, 'cExtensionFunc') as cExtensionFuncMock:
cExtensionFuncMock.return_value = None
code.CodeClass.code_function()
cExtensionFuncMock.assert_called_with()
谢谢