Issue
I found this one out because some of the homework questions I met were tested by docstrings, and it gives me failures.
For example:
def foo(x):
"""
>>> foo(5)
25
>>> foo(6)
36 # Are you sure?
"""
return x**2
if __name__ == '__main__':
import doctest
doctest.testmod(verbose=True)
The example above fails with:
Expected:
36 # are you sure?
Got:
36
I wonder if we are not supposed to add comment in docstring? Or there is a way to make python to ignore the comment in docstring?
Solution
You can just add your comments like below
>>> # comments are ignored
Reference https://docs.python.org/3/library/doctest.html
Note: This must not be a part of output so if you want to add comment then you can use a new line to write your comment. So in your case "36" line must not contain any other string other than output.
Answered By - Viswanath Polaki
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.