123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- --- contrib/python/pytest/py2/_pytest/debugging.py (index)
- +++ contrib/python/pytest/py2/_pytest/debugging.py (working tree)
- @@ -4,6 +4,7 @@ from __future__ import absolute_import
- from __future__ import division
- from __future__ import print_function
-
- +import os
- import argparse
- import pdb
- import sys
- @@ -14,6 +15,42 @@ from _pytest import outcomes
- from _pytest.config.exceptions import UsageError
-
-
- +def import_readline():
- + try:
- + import readline
- + except ImportError:
- + sys.path.append('/usr/lib/python2.7/lib-dynload')
- +
- + try:
- + import readline
- + except ImportError as e:
- + print('can not import readline:', e)
- +
- + import subprocess
- + try:
- + subprocess.check_call('stty icrnl'.split())
- + except OSError as e:
- + print('can not restore Enter, use Control+J:', e)
- +
- +
- +def tty():
- + if os.isatty(1):
- + return
- +
- + fd = os.open('/dev/tty', os.O_RDWR)
- + os.dup2(fd, 0)
- + os.dup2(fd, 1)
- + os.dup2(fd, 2)
- + os.close(fd)
- +
- + old_sys_path = sys.path
- + sys.path = list(sys.path)
- + try:
- + import_readline()
- + finally:
- + sys.path = old_sys_path
- +
- +
- def _validate_usepdb_cls(value):
- """Validate syntax of --pdbcls option."""
- try:
- @@ -249,6 +286,7 @@ class pytestPDB(object):
- @classmethod
- def set_trace(cls, *args, **kwargs):
- """Invoke debugging via ``Pdb.set_trace``, dropping any IO capturing."""
- + tty()
- frame = sys._getframe().f_back
- _pdb = cls._init_pdb("set_trace", *args, **kwargs)
- _pdb.set_trace(frame)
- @@ -262,6 +300,7 @@ class PdbInvoke(object):
- out, err = capman.read_global_capture()
- sys.stdout.write(out)
- sys.stdout.write(err)
- + tty()
- _enter_pdb(node, call.excinfo, report)
-
- def pytest_internalerror(self, excrepr, excinfo):
|