-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
doctest mishandles exceptions raised within generators #42523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If a generator raises an exception while iterating over it, doctest The following code clarifies and reproduces the problem: """Reproduce bug with exceptions in a generator in doctest tests. This bug has been seen to occur in: Linux (RH9): Windows XP: """ def error_generator():
"""Yield 0 to 2 and then try and raise an exception. >>> for j in error_generator():
... print j
0
1
2
Traceback (most recent call last):
Exception: Contrived exception for sake of example
if 1:
raise Exception("Contrived exception for sake of example")
raise StopIteration
if __name__ == '__main__':
# Run the doctest tests.
import sys
import doctest
doctest.testmod(sys.modules['__main__'])
|
Logged In: YES doctest doesn't support mixing "expected normal output" with >>> print 'hi', 1/0
hi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero So there's nothing specific to generators in this, rather """ In any case, it wasn't intended that doctest support this, Edward Loper tried supporting this, as a new feature, before |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: