如何在另一个类方法中模拟方法?

问题描述 投票:0回答:0

我在

notifier
文件中得到了我要测试的方法:

def notify():
    Class_A.another_class_method()

Class A:
    @classmethod
    def prepare():
        helper_method()

    def another_class_method():
        prepare()

我需要模拟 helper_method。 我该怎么做?

我正在尝试像这样修补它:

with patch(
    'notifier.notify.Class_A.another_class_method.prepare.helper_method',
    return_value=True
)

但这行不通。

python unit-testing python-unittest
© www.soinside.com 2019 - 2024. All rights reserved.