summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_doctest.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-07-30 09:23:23 (GMT)
committerGeorg Brandl <georg@python.org>2010-07-30 09:23:23 (GMT)
commit25fbb891d86ecea80d7f12d49a8aa298b9312efa (patch)
tree6c3011a866a9f4c96cee0f4b2f15f8c9ae1615d0 /Lib/test/test_doctest.py
parent46b9afc862974e5855f0ca8a181096945483c86e (diff)
downloadcpython-25fbb891d86ecea80d7f12d49a8aa298b9312efa.zip
cpython-25fbb891d86ecea80d7f12d49a8aa298b9312efa.tar.gz
cpython-25fbb891d86ecea80d7f12d49a8aa298b9312efa.tar.bz2
Issue #8048: Prevent doctests from failing when sys.displayhook has
been reassigned.
Diffstat (limited to 'Lib/test/test_doctest.py')
-rw-r--r--Lib/test/test_doctest.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index 873e495..b6eeaed 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -980,6 +980,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.