0

I am wondering if there is a way to split function calls over multiple lines for doctest. E.g., for something like

>>> result = some_func(some_param=1, another_param=4, a_third_param='super_long_string')

I tried

>>> result = some_func(some_param=1, another_param=4, 
    ...     a_third_param='super_long_string')


>>> result = some_func(some_param=1, another_param=4, \
                       a_third_param='super_long_string')

Or

>>> result = some_func(#doctest: +NORMALIZE_WHITESPACE
             some_param=1, 
             another_param=4, 
             a_third_param='super_long_string')

But both wouldn't work. Any ideas or tips?

Edit: I am running the doctests via nosetests -sv --with-doctest

1 Answers1

2

Your second example is very close to what works for me. After I put a set of ellipses I add five spaces.

The reason I add five spaces is because the first space matches the prompt and the other four match the indentation level.

Here is an example which works for me using python 2.7 and the function you provided.

def some_func(some_param, another_param, a_third_param):
    """
    Does something at least some of the time.

    Examples
    --------

    >>> some_func(
    ...     some_param=1,
    ...     another_param=4,
    ...     a_third_param='super_long_string')
    'Worked'
    """
    return 'Worked'

if __name__ == "__main__":
    import doctest
    doctest.testmod()
erik-e
  • 3,721
  • 1
  • 21
  • 19
  • Sorry, that was a typo in my example above. I also tried the 5 whitespaces after `...` and still the same problem `has inconsistent leading whitespace` but thanks for the help! –  Feb 26 '15 at 07:40
  • I guess this problem is specific to the `nosetests -sv --with-doctest` command. I am using python 3.4.0 and nose 1.3.4 –  Feb 26 '15 at 07:42