From 924a9667e16fc64483e264a3ea35915982ffcb41 Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Thu, 24 Dec 2015 14:56:57 -0500 Subject: [PATCH] Make sure readline has been imported before duping any stdio handles--otherwise pyreadline fails to connect to the correct handle for the console's stdout/in. --- _pytest/capture.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/_pytest/capture.py b/_pytest/capture.py index f0fa72f46..478d475f1 100644 --- a/_pytest/capture.py +++ b/_pytest/capture.py @@ -308,6 +308,14 @@ class FDCapture: """ Capture IO to/from a given os-level filedescriptor. """ def __init__(self, targetfd, tmpfile=None): + # ensure readline is imported so that it attaches to the correct + # stdio handles on Windows + if targetfd in (0, 1, 2): + try: + import readline + except ImportError: + pass + self.targetfd = targetfd try: self.targetfd_save = os.dup(self.targetfd)