10

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')
    """
...
Alexey Shrub
  • 1,216
  • 13
  • 22
m3ta
  • 171
  • 7
  • 1
    [*"minimock is a simple library for doing Mock objects with doctest"*](https://pypi.python.org/pypi/MiniMock) – jonrsharpe Dec 22 '16 at 18:04
  • 1
    Thanks, I guess I am just confused about making the documentation confusing by introducing Mocks. – m3ta Dec 23 '16 at 15:06
  • 5
    Why not keep simple examples in the docstrings but migrate your actual tests to a proper test runner? Doctests are good for some things but you're evidently reaching the edges of that. – jonrsharpe Dec 23 '16 at 15:27
  • Yeah that's fair enough! Thanks! – m3ta Dec 23 '16 at 18:08

0 Answers0