Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
25fbb891
Commit
25fbb891
authored
Jul 30, 2010
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #8048: Prevent doctests from failing when sys.displayhook has
been reassigned.
parent
46b9afc8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
0 deletions
+37
-0
Lib/doctest.py
Lib/doctest.py
+5
-0
Lib/test/test_doctest.py
Lib/test/test_doctest.py
+29
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/doctest.py
View file @
25fbb891
...
...
@@ -1379,12 +1379,17 @@ class DocTestRunner:
self
.
save_linecache_getlines
=
linecache
.
getlines
linecache
.
getlines
=
self
.
__patched_linecache_getlines
# Make sure sys.displayhook just prints the value to stdout
save_displayhook
=
sys
.
displayhook
sys
.
displayhook
=
sys
.
__displayhook__
try
:
return
self
.
__run
(
test
,
compileflags
,
out
)
finally
:
sys
.
stdout
=
save_stdout
pdb
.
set_trace
=
save_set_trace
linecache
.
getlines
=
self
.
save_linecache_getlines
sys
.
displayhook
=
save_displayhook
if
clear_globs
:
test
.
globs
.
clear
()
import
builtins
...
...
Lib/test/test_doctest.py
View file @
25fbb891
...
...
@@ -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.
...
...
Misc/NEWS
View file @
25fbb891
...
...
@@ -475,6 +475,9 @@ C-API
Library
-------
- Issue #8048: Prevent doctests from failing when sys.displayhook has
been reassigned.
- Issue #8015: In pdb, do not crash when an empty line is entered as
a breakpoint command.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment