This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: doctest assumes sys.displayhook hasn't been touched
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.2, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: flox, georg.brandl, noam
Priority: normal Keywords: patch

Created on 2010-03-03 08:17 by noam, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit noam, 2010-03-03 08:17 Diff for (from python 2.6)
diff noam, 2010-03-04 22:00 Patch against Python 2, includes a test.
better.patch noam, 2010-03-19 09:09 Better patch
Messages (4)
msg100334 - (view) Author: Noam Yorav-Raphael (noam) Date: 2010-03-03 08:17

This bug is the cause of a bug reported about DreamPie:

DreamPie ( changes sys.displayhook so that values will be sent to the parent process instead of being printed in stdout. This causes doctest to fail when run from DreamPie, because it implicitly assumes that sys.displayhook writes the values it gets to sys.stdout. This is why doctest replaces sys.stdout with its own file-like object, which is ready to receive the printed values.

The solution is simply to replace sys.displayhook with a function that will do the expected thing, just like sys.stdout is replaced. The patch I attach does exactly this.

msg100423 - (view) Author: Noam Yorav-Raphael (noam) Date: 2010-03-04 22:00
Ok, here's a patch (against current svn of Python 2) with a test case.

I had to fix three tests which combined pdb and doctest, since now, when run under doctest, pdb steps into the displayhook because it's a Python function and not a built-in function. The fix is just to return from the displayhook.

If you wish, I can prepare a patch for Python 3.
msg101312 - (view) Author: Noam Yorav-Raphael (noam) Date: 2010-03-19 09:09
Here is a better and much shorter patch: I use sys.__displayhook__ instead of implementing it in Python, which has the nice side effect of not changing pdb behaviour.
msg112054 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-30 09:23
Thanks, applied to 3k in r83268.
Date User Action Args
2022-04-11 14:56:58adminsetgithub: 52296
2010-07-30 09:23:29georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112054

resolution: fixed
2010-03-19 09:09:25noamsetfiles: + better.patch

messages: + msg101312
2010-03-04 22:00:44noamsetfiles: + diff

messages: + msg100423
2010-03-03 12:08:35floxsetpriority: normal
nosy: + flox
stage: test needed

versions: + Python 2.7, Python 3.2
2010-03-03 08:17:34noamcreate