[ACCEPTED]-Python doctest: Skip entire block?-doctest
Wrap the example in a function and then 1 skip the function call:
"""
>>> def example():
... from packagename import module
... module.show_real_world_usage()
...
>>> example() # doctest: +SKIP
'Hello world!'
"""
My solution has been to trim the the 3-character 6 >>>
and ...
leaders where I want doctest to skip 5 over them, making them 2-characters.
So
"""
>>> from packagename import module
>>> module.show_real_world_usage()
'Hello world!'
"""
has 4 become
"""
>> from packagename import module
>> module.show_real_world_usage()
'Hello world!'
"""
Epydoc doesn't display this as nicely 3 as it does doctests, but I can live with 2 this. A skip-until-further-notice directive 1 in doctest would be welcome though.
with xdoctest
you can use this >>> # doctest: +SKIP
as first line:
def some_function():
"""
Some documentation
Examples:
>>> # doctest: +SKIP
>>> do_something()
>>> do_something_else()
>>> and_do_this()
"""
unfortunately 2 doctest
itself crashes (and sphinx prints that 1 as >>>
instead of completely ignoring it).
If it's not an actual doctest by any means, you 7 can just assign the value to a variable. For 6 example,
example_usage = """
Real-world example:
# python2.5
...
"""
will cause that "test" to not be 5 evaluated.
It might be better to use __example_usage__
(or 4 something else surrounded by double-underscores) so 3 that it's clear that's a "magic" variable 2 and not a variable to be used within the 1 context of the script.
A small workaround building upon RobM's answer preserves 2 the display/formatting by starting the example 1 with a >>> like that:
"""
>>>
>> from packagename import module
>> module.show_real_world_usage()
'Hello world!'
"""
I went for the # doctest: +SKIP
on every line
def doc_test_test():
"""Doc tests
Examples:
>>> do_something1() # doctest: +SKIP
>>> do_something2() # doctest: +SKIP
>>> do_something3() # doctest: +SKIP
"""
pass
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.