Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent readline from bugging out when the editline backend is used #12961

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/_pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@
pass


def _readline_workaround() -> None:
"""Ensure :mod:`readline` is imported as it fails otherwise when the
``editline`` (``libedit``) backend is used.

Since Python 3.13, :mod:`readline` is imported at the root of the
:mod:`pdb` module, as a side effect of importing :mod:`rlcompleter`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:mod:`pdb` module, as a side effect of importing :mod:`rlcompleter`.
:mod:`pdb` module, as a side effect of importing :mod:`rlcompleter`.
See #12888 for details.

"""
if sys.version_info >= (3, 13):
try:
import readline # noqa: F401
except ImportError:
pass

Check warning on line 94 in src/_pytest/capture.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/capture.py#L93-L94

Added lines #L93 - L94 were not covered by tests


def _windowsconsoleio_workaround(stream: TextIO) -> None:
"""Workaround for Windows Unicode console handling.

Expand Down Expand Up @@ -141,6 +155,7 @@
if ns.capture == "fd":
_windowsconsoleio_workaround(sys.stdout)
_colorama_workaround()
_readline_workaround()
pluginmanager = early_config.pluginmanager
capman = CaptureManager(ns.capture)
pluginmanager.register(capman, "capturemanager")
Expand Down
Loading