问题
I am using doctests. I am wondering what is the correct way to doctest a function that performs an external action (e.g. sends email, connects to a server, etc)? Using Mock seems like the answer but it will muddy up the doc string of the function.
For example:
class SSHConnection(BaseConnection):
"""Provides basic SSH functions.
>>> host = '127.0.0.1'
>>> port = 22
>>> username = 'user'
>>> password = 'password'
>>> ssh = SSHConnection(host, username, password, port)
>>> ssh.execute('uname -a')
"""
...
来源:https://stackoverflow.com/questions/41289247/using-mocks-inside-doctests