Skip to content

Commit 137aab8

Browse files
Clear any prior readline imports in unit test
Since the tests are run in Python's non-interactive mode we don't expect readline to be imported. Unfortunately it manages to sneak in on the latest Python. In Python 3.13.0 pdb now imports rlcompleter to standardise its command-line completion (see python/cpython#112948). This is fine, but pytest also imports pdb as part of its configuration as it wants to monkey patch it in `pytest/src/_pytest/debugging.py`... This causes readline to be imported before test.py is imported, thwarting the `import_alternative_readline_module` function. The solution is to clear any preloaded readline modules at the start of the unit test by hacking it out of `sys.modules`.
1 parent 87a641d commit 137aab8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tests/test.py

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
import gnureadline
55

6+
# Since the tests are non-interactive we don't expect readline to be imported.
7+
# Unfortunately it manages to sneak in on Python 3.13.0 via pytest and pdb (see
8+
# python/cpython#112948 and pytest/src/_pytest/debugging.py). Enforce its absence.
9+
if 'readline' in sys.modules:
10+
del sys.modules['readline']
11+
612

713
def import_alternative_readline_module():
814
"""This forcibly imports our alternative readline.py module over the standard one."""

0 commit comments

Comments
 (0)