在Python内部函数中导入的补丁类

我有:

folder / cats.py

class Cat(object):
    def __init__(self,color):
        self.color = color

    def meow():
        pass

folder / something.py

def something():
    from folder.cats import Cat

    scootish_fold = Cat(color='Black')
    scootish_fold.meow()

如何修补meow()

我尝试过:

@patch('folder.something.Cat.meow')
def test_meow(self,cat_meow_patch):
    cat_patch.return_value = 'MEOWW!'

但是我不断收到AttributeError

lizihao3hao 回答:在Python内部函数中导入的补丁类

您始终可以使用其原始包/模块路径来修补模块/类:

@patch('folder.cats.Cat.meow')
def test_meow(self,cat_meow_patch):
    cat_patch.return_value = 'MEOWW!'
本文链接:https://www.f2er.com/3162945.html

大家都在问