How to mock Python static methods and class methods

前端 未结 2 888
鱼传尺愫
鱼传尺愫 2021-02-07 17:14

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

class Calculator(objec         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 18:00

    One way to do it is

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

提交回复
热议问题