如何使用unittest模拟来测试初始化​​类的过程?

时间:2018-10-18 14:56:41

标签: python testing mocking pytest

class A:
    def __init__(self, string):
        pass

def make_class(String):
     ...
     dealing with string to construct instance A
     ...
     return A(s)


def test_make_class():
     s = inputString
     a = unittest.mock.MagicMock("a", spec=A)
     b = make_class(s)
     assert a is b

问题是我有一个类A和一个函数make_class来构造类A的实例。我需要make_class的原因是我需要将输入字符串处理为正确的格式。但是我该如何测试我的函数make_class。我想我需要生成一个模拟实例来替换make_class(s​​)中的返回值,但是我该怎么做呢?

0 个答案:

没有答案