How to mock Python static methods and class methods

前端 未结 3 2029
不知归路
不知归路 2021-02-07 17:18

How do I mock a class that has unbound methods? For example, this class has a @classmethod and a @staticmethod:

class Calculator(objec         


        
3条回答
  •  误落风尘
    2021-02-07 17:58

    One way to do it is

    def test_increment(mocker):
        mocker.patch.object(Calculator, attribute='increment', return_value=10)
        ...actual test code...
    

提交回复
热议问题