mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #8048: Prevent doctests from failing when sys.displayhook has
been reassigned.
This commit is contained in:
parent
46b9afc862
commit
25fbb891d8
3 changed files with 37 additions and 0 deletions
|
@ -979,6 +979,35 @@ unexpected exception:
|
|||
...
|
||||
ZeroDivisionError: integer division or modulo by zero
|
||||
TestResults(failed=1, attempted=1)
|
||||
"""
|
||||
def displayhook(): r"""
|
||||
Test that changing sys.displayhook doesn't matter for doctest.
|
||||
|
||||
>>> import sys
|
||||
>>> orig_displayhook = sys.displayhook
|
||||
>>> def my_displayhook(x):
|
||||
... print('hi!')
|
||||
>>> sys.displayhook = my_displayhook
|
||||
>>> def f():
|
||||
... '''
|
||||
... >>> 3
|
||||
... 3
|
||||
... '''
|
||||
>>> test = doctest.DocTestFinder().find(f)[0]
|
||||
>>> r = doctest.DocTestRunner(verbose=False).run(test)
|
||||
>>> post_displayhook = sys.displayhook
|
||||
|
||||
We need to restore sys.displayhook now, so that we'll be able to test
|
||||
results.
|
||||
|
||||
>>> sys.displayhook = orig_displayhook
|
||||
|
||||
Ok, now we can check that everything is ok.
|
||||
|
||||
>>> r
|
||||
TestResults(failed=0, attempted=1)
|
||||
>>> post_displayhook is my_displayhook
|
||||
True
|
||||
"""
|
||||
def optionflags(): r"""
|
||||
Tests of `DocTestRunner`'s option flag handling.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue