Skip to content

Commit ad69a67

Browse files
committed
Prevent readline from bugging out when the editline backend is used
1 parent 76b8870 commit ad69a67

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/_pytest/capture.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ def _colorama_workaround() -> None:
8080
pass
8181

8282

83+
def _readline_workaround() -> None:
84+
"""Ensure :mod:`readline` is imported as it fails otherwise when the
85+
``editline`` (``libedit``) backend is used.
86+
87+
Since Python 3.13, :mod:`readline` is imported at the root of the
88+
:mod:`pdb` module, as a side effect of importing :mod:`rlcompleter`.
89+
"""
90+
if sys.version_info >= (3, 13):
91+
try:
92+
import readline # noqa: F401
93+
except ImportError:
94+
pass
95+
96+
8397
def _windowsconsoleio_workaround(stream: TextIO) -> None:
8498
"""Workaround for Windows Unicode console handling.
8599
@@ -141,6 +155,7 @@ def pytest_load_initial_conftests(early_config: Config) -> Generator[None]:
141155
if ns.capture == "fd":
142156
_windowsconsoleio_workaround(sys.stdout)
143157
_colorama_workaround()
158+
_readline_workaround()
144159
pluginmanager = early_config.pluginmanager
145160
capman = CaptureManager(ns.capture)
146161
pluginmanager.register(capman, "capturemanager")

0 commit comments

Comments
 (0)