html tool

2019年7月15日星期一

mock py2.7 for MagicMock使用


https://docs.python.org/3/library/unittest.mock.html

[popexizhi:
1.python3.0 的doc,自己用2.7测试,发现这个
import magicmock
mock = magicmock.MagicMock()
提示没有这个方法,
最后参考 https://www.programcreek.com/python/example/14270/mock.MagicMock
 m_resp = mock.MagicMock()
是mock 中的 MagicMock :),
而这个magicmock的help中有
PACKAGE CONTENTS
    ClientAPI (package)
    Exceptions
    Http (package)
    Log (package)
    Sample (package)
    Utils
倒是只得试试
]
Mock supports the mocking of Python magic methods. The easiest way of using magic methods is with the MagicMock class. It allows you to do things like:
>>> mock = MagicMock() ------------------------------[popexizhi:1]
>>> mock.__str__.return_value = 'foobarbaz'
>>> str(mock)
'foobarbaz'
>>> mock.__str__.assert_called_with()

没有评论:

发表评论