且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python中实例变量的模拟方法

更新时间:2023-10-21 21:41:58

可以通过模拟操作返回值来完成

Can be done by mock the action return value

class TestHandler(unittest.TestCase):

@mock.patch('__main__.Client.action')
def test_example_client_action_false(self, mock_client_action):
    """Test Example When Action is False"""
    mock_client_action.return_value = False
    handler = Handler()
    self.assertFalse(handler.example())