From 0e39bd1a16f2ff7eba2d911112e2b64cd5d2d382 Mon Sep 17 00:00:00 2001 From: Mikhail Trifonov Date: Thu, 23 Jun 2016 02:15:26 +0300 Subject: [PATCH] set pdb by cmd flag when exception was raised --- seismograph/case.py | 4 ++++ seismograph/config.py | 7 +++++++ seismograph/program.py | 1 + seismograph/runnable.py | 12 ++++++++++++ seismograph/suite.py | 1 + 5 files changed, 25 insertions(+) diff --git a/seismograph/case.py b/seismograph/case.py index 1da4261..73814fd 100644 --- a/seismograph/case.py +++ b/seismograph/case.py @@ -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) @@ -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( diff --git a/seismograph/config.py b/seismograph/config.py index 45dbd9f..76e0659 100644 --- a/seismograph/config.py +++ b/seismograph/config.py @@ -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 diff --git a/seismograph/program.py b/seismograph/program.py index a021b1a..6961cdc 100644 --- a/seismograph/program.py +++ b/seismograph/program.py @@ -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, diff --git a/seismograph/runnable.py b/seismograph/runnable.py index adf76a1..17a7051 100644 --- a/seismograph/runnable.py +++ b/seismograph/runnable.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import sys from functools import wraps from collections import OrderedDict from contextlib import contextmanager @@ -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__() diff --git a/seismograph/suite.py b/seismograph/suite.py index 4248ff3..1d012f5 100644 --- a/seismograph/suite.py +++ b/seismograph/suite.py @@ -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,