From ad69a671389ab8ff7f74b9988fc6268c77fd77ee Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:29:44 +0100 Subject: [PATCH] Prevent `readline` from bugging out when the `editline` backend is used --- src/_pytest/capture.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index 2ac3b6bbc7f..711bc1174ab 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -80,6 +80,20 @@ def _colorama_workaround() -> None: 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`. + """ + if sys.version_info >= (3, 13): + try: + import readline # noqa: F401 + except ImportError: + pass + + def _windowsconsoleio_workaround(stream: TextIO) -> None: """Workaround for Windows Unicode console handling. @@ -141,6 +155,7 @@ def pytest_load_initial_conftests(early_config: Config) -> Generator[None]: if ns.capture == "fd": _windowsconsoleio_workaround(sys.stdout) _colorama_workaround() + _readline_workaround() pluginmanager = early_config.pluginmanager capman = CaptureManager(ns.capture) pluginmanager.register(capman, "capturemanager")