05-support-readline.patch 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --- contrib/python/pytest/py3/_pytest/debugging.py (index)
  2. +++ contrib/python/pytest/py3/_pytest/debugging.py (working tree)
  3. @@ -3,2 +3,3 @@ from __future__ import absolute_import
  4. import functools
  5. +import os
  6. import sys
  7. @@ -32,2 +33,38 @@ from _pytest import outcomes
  8. +def import_readline():
  9. + try:
  10. + import readline
  11. + except ImportError:
  12. + sys.path.append('/usr/lib/python2.7/lib-dynload')
  13. +
  14. + try:
  15. + import readline
  16. + except ImportError as e:
  17. + print('can not import readline:', e)
  18. +
  19. + import subprocess
  20. + try:
  21. + subprocess.check_call('stty icrnl'.split())
  22. + except OSError as e:
  23. + print('can not restore Enter, use Control+J:', e)
  24. +
  25. +
  26. +def tty():
  27. + if os.isatty(1):
  28. + return
  29. +
  30. + fd = os.open('/dev/tty', os.O_RDWR)
  31. + os.dup2(fd, 0)
  32. + os.dup2(fd, 1)
  33. + os.dup2(fd, 2)
  34. + os.close(fd)
  35. +
  36. + old_sys_path = sys.path
  37. + sys.path = list(sys.path)
  38. + try:
  39. + import_readline()
  40. + finally:
  41. + sys.path = old_sys_path
  42. +
  43. +
  44. def _validate_usepdb_cls(value: str) -> Tuple[str, str]:
  45. @@ -280,2 +317,3 @@ class pytestPDB(object):
  46. """Invoke debugging via ``Pdb.set_trace``, dropping any IO capturing."""
  47. + tty()
  48. frame = sys._getframe().f_back
  49. @@ -295,2 +333,3 @@ class PdbInvoke(object):
  50. sys.stdout.write(err)
  51. + tty()
  52. assert call.excinfo is not None