diff --git a/testplan/common/report/base.py b/testplan/common/report/base.py index b570b7415..24bf2d9e1 100644 --- a/testplan/common/report/base.py +++ b/testplan/common/report/base.py @@ -70,6 +70,7 @@ def __exit__(self, exc_type, exc_value, tb): str(exc_value), ) self.report.status_override = Status.SKIPPED + return True elif issubclass(exc_type, self.exception_classes): # Custom exception message with extra args exc_msg = "".join( @@ -79,7 +80,7 @@ def __exit__(self, exc_type, exc_value, tb): if self.fail: self.report.status_override = Status.ERROR - return True + return True @total_ordering diff --git a/testplan/testing/base.py b/testplan/testing/base.py index 8642d98d0..36281b868 100644 --- a/testplan/testing/base.py +++ b/testplan/testing/base.py @@ -416,36 +416,33 @@ def propagate_tag_indices(self) -> None: self.report.propagate_tag_indices() def _init_context(self) -> None: - with self.resources.set_self_exception(): - if callable(self.cfg.initial_context): - self.resources._initial_context = self.cfg.initial_context() - else: - self.resources._initial_context = self.cfg.initial_context + if callable(self.cfg.initial_context): + self.resources._initial_context = self.cfg.initial_context() + else: + self.resources._initial_context = self.cfg.initial_context def _build_environment(self) -> None: # build environment only once in interactive mode if self._env_built: return - with self.resources.set_self_exception(): - if callable(self.cfg.environment): - drivers = self.cfg.environment() - else: - drivers = self.cfg.environment - for driver in drivers: - driver.parent = self - driver.cfg.parent = self.cfg - self.resources.add(driver) + if callable(self.cfg.environment): + drivers = self.cfg.environment() + else: + drivers = self.cfg.environment + for driver in drivers: + driver.parent = self + driver.cfg.parent = self.cfg + self.resources.add(driver) self._env_built = True def _set_dependencies(self) -> None: - with self.resources.set_self_exception(): - if callable(self.cfg.dependencies): - deps = parse_dependency(self.cfg.dependencies()) - else: - deps = self.cfg.dependencies - self.resources.set_dependency(deps) + if callable(self.cfg.dependencies): + deps = parse_dependency(self.cfg.dependencies()) + else: + deps = self.cfg.dependencies + self.resources.set_dependency(deps) def _start_resource(self) -> None: if len(self.resources) == 0: diff --git a/testplan/testing/environment/base.py b/testplan/testing/environment/base.py index a53487dcc..5c787c69f 100644 --- a/testplan/testing/environment/base.py +++ b/testplan/testing/environment/base.py @@ -55,19 +55,10 @@ class TestEnvironment(Environment): def __init__(self, parent: Optional["Test"] = None): super().__init__(parent) - self.__dict__["self_exception"] = None # Optional[Exception] self.__dict__["_orig_dependency"] = None # Optional[DriverDepGraph] self.__dict__["_rt_dependency"] = None # Optional[DriverDepGraph] self.__dict__["_pocketwatches"] = {} # Dict[str, DriverPocketwatch] - @contextmanager - def set_self_exception(self): - try: - yield - except Exception as e: - self.self_exception = e - raise - def set_dependency(self, dependency: Optional[DriverDepGraph]): if dependency is None: return diff --git a/testplan/testing/multitest/base.py b/testplan/testing/multitest/base.py index e8ed7f586..d418b6bbd 100644 --- a/testplan/testing/multitest/base.py +++ b/testplan/testing/multitest/base.py @@ -592,8 +592,13 @@ def skip_step(self, step) -> bool: or self.resources.stop_exceptions or self._get_error_logs() ) - elif self.resources.self_exception is not None: - # self of status ERROR + elif "_start_resource" not in self.result.step_results and any( + map( + lambda x: isinstance(x, Exception), + self.result.step_results.values(), + ) + ): + # exc before _start_resource return True elif step in ( self._start_resource, diff --git a/tests/unit/testplan/common/report/test_base.py b/tests/unit/testplan/common/report/test_base.py index c13c7bf1d..cda4f2ea9 100644 --- a/tests/unit/testplan/common/report/test_base.py +++ b/tests/unit/testplan/common/report/test_base.py @@ -37,7 +37,7 @@ def test_exception_logger_suppression(): @disable_log_propagation(LOGGER) def test_exception_logger_reraise(): """ - ExceptionLoggerBase should raise the exception without logging + ExceptionLogger.* should raise the exception without logging if it doesn't match `exception_classes`. """ rep = DummyReport() @@ -50,6 +50,16 @@ def test_exception_logger_reraise(): with rep.logged_exceptions(IndexError): raise KeyError("bar") # raised + rep = DummyReportGroup() + + with pytest.raises(KeyError): + + with rep.logged_exceptions(IndexError): + raise IndexError("foo") # suppressed + + with rep.logged_exceptions(IndexError): + raise KeyError("bar") # raised + class TestReport: def test_equality(self):