Skip to content

Commit ca82214

Browse files
committed
pytester: workaround issue causing spawn to crash or hang
In pytester tests, pytest stashes & restores the sys.modules for each test. So if the test imports a new module, it is initialized anew each time. Turns out the readline module isn't multi-init safe, which causes pytester.spawn to crash or hang. So preserve it as a workaround.
1 parent 897f151 commit ca82214

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

changelog/7913.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed a crash or hang in ``pytester.spawn`` when the ``readline`` module is involved.

src/_pytest/pytester.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,11 @@ def __take_sys_modules_snapshot(self) -> SysModulesSnapshot:
707707
# Some zope modules used by twisted-related tests keep internal state
708708
# and can't be deleted; we had some trouble in the past with
709709
# `zope.interface` for example.
710+
#
711+
# Preserve readline due to https://bugs.python.org/issue41033.
712+
# pexpect issues a SIGWINCH.
710713
def preserve_module(name):
711-
return name.startswith("zope")
714+
return name.startswith(("zope", "readline"))
712715

713716
return SysModulesSnapshot(preserve=preserve_module)
714717

0 commit comments

Comments
 (0)