Using Mocks inside Doctests?

吃可爱长大的小学妹 提交于 2020-01-02 03:45:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!