Skip to content

Commit

Permalink
set pdb by cmd flag when exception was raised
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Trifonov committed Jun 22, 2016
1 parent 4d4f165 commit 0e39bd1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions seismograph/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,18 +764,21 @@ def __run__(self, result):
result_proxy.current_state.should_stop = True
raise
except Skip as s:
runnable.set_debug_if_allowed(self.config)
was_success = False
self.__context.on_skip(self, s.message, result_proxy)
result_proxy.add_skip(
self, s.message, timer(),
)
except AssertionError as fail:
runnable.set_debug_if_allowed(self.config)
was_success = False
self.__context.on_fail(fail, self, result_proxy)
result_proxy.add_fail(
self, traceback.format_exc(), timer(), fail,
)
except BaseException as error:
runnable.set_debug_if_allowed(self.config)
was_success = False
self.__context.on_error(error, self, result_proxy)
self.__context.on_any_error(error, self, result_proxy)
Expand All @@ -794,6 +797,7 @@ def __run__(self, result):
except ALLOW_RAISED_EXCEPTIONS:
raise
except BaseException as error:
runnable.set_debug_if_allowed(self.config)
self.__context.on_context_error(error, self, result_proxy)
self.__context.on_any_error(error, self, result_proxy)
result_proxy.add_error(
Expand Down
7 changes: 7 additions & 0 deletions seismograph/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ def create_option_parser():
default=False,
help='Use multiprocessing groups for run.',
)
run_group.add_option(
'--pdb',
dest='PDB',
action='store_true',
default=False,
help='Set trace after raise exception on runnable object.',
)
parser.add_option_group(run_group)

return parser
Expand Down
1 change: 1 addition & 0 deletions seismograph/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def __run__(self):
except ALLOW_RAISED_EXCEPTIONS:
raise
except BaseException as error:
runnable.set_debug_if_allowed(self.config)
self.__context.on_error(error, self, self.__result)
self.__result.add_error(
self, traceback.format_exc(), timer(), error,
Expand Down
12 changes: 12 additions & 0 deletions seismograph/runnable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import sys
from functools import wraps
from collections import OrderedDict
from contextlib import contextmanager
Expand All @@ -24,6 +25,17 @@ def stopped_on(runnable, method_name=None):
return runnable.__stopped_on__()


def set_debug_if_allowed(config):
if config.PDB:
try:
import ipdb as pdb
except ImportError:
import pdb

_, _, tb = sys.exc_info()
pdb.post_mortem(tb)


def is_run(runnable):
return runnable.__is_run__()

Expand Down
1 change: 1 addition & 0 deletions seismograph/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def __run__(self, result):
except ALLOW_RAISED_EXCEPTIONS:
raise
except BaseException as error:
runnable.set_debug_if_allowed(self.config)
self.__context.on_error(error, self, result_proxy)
result_proxy.add_error(
self, traceback.format_exc(), timer(), error,
Expand Down

0 comments on commit 0e39bd1

Please sign in to comment.