Skip to content

Commit

Permalink
really address review comments; bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyu-ms committed Jul 12, 2024
1 parent 6387774 commit 7451189
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 33 deletions.
3 changes: 2 additions & 1 deletion testplan/common/report/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
37 changes: 17 additions & 20 deletions testplan/testing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 0 additions & 9 deletions testplan/testing/environment/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions testplan/testing/multitest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion tests/unit/testplan/common/report/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down

0 comments on commit 7451189

Please sign in to comment.