* Moved workaround to its own function, mostly for the sake of adding
a more descriptive docstring (the workaround itself is just to import readline earlier). I removed the conditional on targetfd from the workaround since it doesn't really matter. * Added # noqa marker. * Added changelog entry, and self to authors.
This commit is contained in:
parent
924a9667e1
commit
6e170a4a1c
1
AUTHORS
1
AUTHORS
|
@ -31,6 +31,7 @@ Eduardo Schettino
|
||||||
Elizaveta Shashkova
|
Elizaveta Shashkova
|
||||||
Eric Hunsberger
|
Eric Hunsberger
|
||||||
Eric Siegerman
|
Eric Siegerman
|
||||||
|
Erik M. Bray
|
||||||
Florian Bruhin
|
Florian Bruhin
|
||||||
Floris Bruynooghe
|
Floris Bruynooghe
|
||||||
Gabriel Reis
|
Gabriel Reis
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
this was a regression failing plugins combinations
|
this was a regression failing plugins combinations
|
||||||
like pytest-pep8 + pytest-flakes
|
like pytest-pep8 + pytest-flakes
|
||||||
|
|
||||||
|
- Workaround for exception that occurs in pyreadline when using
|
||||||
|
``--pdb`` with standard I/O capture enabled.
|
||||||
|
|
||||||
2.8.5
|
2.8.5
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
|
@ -308,14 +308,7 @@ class FDCapture:
|
||||||
""" Capture IO to/from a given os-level filedescriptor. """
|
""" Capture IO to/from a given os-level filedescriptor. """
|
||||||
|
|
||||||
def __init__(self, targetfd, tmpfile=None):
|
def __init__(self, targetfd, tmpfile=None):
|
||||||
# ensure readline is imported so that it attaches to the correct
|
readline_workaround()
|
||||||
# stdio handles on Windows
|
|
||||||
if targetfd in (0, 1, 2):
|
|
||||||
try:
|
|
||||||
import readline
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.targetfd = targetfd
|
self.targetfd = targetfd
|
||||||
try:
|
try:
|
||||||
self.targetfd_save = os.dup(self.targetfd)
|
self.targetfd_save = os.dup(self.targetfd)
|
||||||
|
@ -450,3 +443,28 @@ class DontReadFromInput:
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def readline_workaround():
|
||||||
|
"""
|
||||||
|
Ensure readline is imported so that it attaches to the correct stdio
|
||||||
|
handles on Windows.
|
||||||
|
|
||||||
|
Pdb uses readline support where available--when not running from the Python
|
||||||
|
prompt, the readline module is not imported until running the pdb REPL. If
|
||||||
|
running py.test with the --pdb option this means the readline module is not
|
||||||
|
imported until after I/O capture has been started.
|
||||||
|
|
||||||
|
This is a problem for pyreadline, which is often used to implement readline
|
||||||
|
support on Windows, as it does not attach to the correct handles for stdout
|
||||||
|
and/or stdin if they have been redirected by the FDCapture mechanism. This
|
||||||
|
workaround ensures that readline is imported before I/O capture is setup so
|
||||||
|
that it can attach to the actual stdin/out for the console.
|
||||||
|
|
||||||
|
See https://github.com/pytest-dev/pytest/pull/1281
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
import readline # noqa
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
Loading…
Reference in New Issue