1 回答

TA贡献1963条经验 获得超6个赞
一个常见的问题是模拟函数的使用过于复杂。您几乎可以像对待另一个类方法一样对待它们。在您的情况下,abstractmethod装饰器可能会造成混乱。
这接近您可能需要的东西。
class MockSharedFunctions(SharedFunctions):
def one_important_universal_function(**args):
return 0
class TestSharedFunctions(unittest.TestCase):
def test_first_function(self):
mock = MockSharedFunctions()
mock_output = firstfunction(**args)
mock_stuff = mock.stuff
self.assertTrue(True)
self.assetEqual(mock_output, expected)
self.assetEqual(mock_stuff, expected)
def test_second_function(self):
mock = MockSharedFunctions()
mock.stuff = some_value
mock_output = second_function(**args)
self.assetEqual(mock_output, expected)
self.assertTrue(True)
if __name__ == "__main__":
unittest.main()
在这里,MockSharedFunctions您已经在继承SharedFunctions. 作为one_important_universal_function一个抽象方法,它需要被定义。
添加回答
举报