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 15, 2024
1 parent 6387774 commit 1356e61
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 36 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
12 changes: 8 additions & 4 deletions testplan/testing/multitest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,13 +587,17 @@ def skip_step(self, step) -> bool:
"""Check if a step should be skipped."""
if step == self._run_error_handler:
return not (
self.resources.self_exception is not None
or self.resources.start_exceptions
self.resources.start_exceptions
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
1 change: 0 additions & 1 deletion tests/unit/testplan/testing/multitest/test_multitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,6 @@ def test_skip_steps():
)

mt.run()
assert mt.resources.self_exception is not None
assert all(
map(
lambda x: x in mt.result.step_results,
Expand Down

0 comments on commit 1356e61

Please sign in to comment.