Skip to content

Commit

Permalink
Merge pull request #68 from cjwatson/ipdb
Browse files Browse the repository at this point in the history
Use ipdb instead of pdb if available
  • Loading branch information
cjwatson committed Jan 6, 2018
2 parents aa7c9d1 + 54a789f commit dae4678
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
``optparse``. See `issue 61
<https://github.com/zopefoundation/zope.testrunner/issues/61>`_.

- Use ipdb instead of pdb for post-mortem debugging if available
(`#10 <https://github.com/zopefoundation/zope.testrunner/issues/10>`_).

4.8.1 (2017-11-12)
==================

Expand Down
32 changes: 30 additions & 2 deletions src/zope/testrunner/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,38 @@
from __future__ import print_function

import doctest
import sys
import io
import pdb
import sys
import threading
import traceback

try:
import ipdb
_ipdb_state = threading.local()
except ImportError:
ipdb = None

import zope.testrunner.interfaces


def _use_ipdb():
"""Check whether ipdb is usable."""
global _ipdb_ok
if ipdb is None:
return False
if getattr(_ipdb_state, 'ok', None) is None:
_ipdb_state.ok = False
if hasattr(sys.stdin, 'isatty') and sys.stdin.isatty():
try:
sys.stdin.fileno()
except (AttributeError, io.UnsupportedOperation):
pass
else:
_ipdb_state.ok = True
return _ipdb_state.ok


def post_mortem(exc_info):
err = exc_info[1]
if isinstance(err, (doctest.UnexpectedException, doctest.DocTestFailure)):
Expand All @@ -47,7 +72,10 @@ def post_mortem(exc_info):
exc_info = sys.exc_info()

print(''.join(traceback.format_exception_only(exc_info[0], exc_info[1])))
pdb.post_mortem(exc_info[2])
if _use_ipdb():
ipdb.post_mortem(exc_info[2])
else:
pdb.post_mortem(exc_info[2])
raise zope.testrunner.interfaces.EndRun()


Expand Down

0 comments on commit dae4678

Please sign in to comment.