Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If run_if throws exception (not intentionally), test will terminate with pass outcome #1203

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions openhtf/core/phase_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,18 @@ def _execute_phase_once(
) -> Tuple[PhaseExecutionOutcome, Optional[pstats.Stats]]:
"""Executes the given phase, returning a PhaseExecutionOutcome."""
# Check this before we create a PhaseState and PhaseRecord.
if phase_desc.options.run_if and not phase_desc.options.run_if():
self.logger.debug('Phase %s skipped due to run_if returning falsey.',
if phase_desc.options.run_if:
try:
run_phase = phase_desc.options.run_if()
except Exception: # pylint: disable=broad-except
# Allow graceful termination
return PhaseExecutionOutcome(phase_descriptor.PhaseResult.STOP), None

if not run_phase:
self.logger.debug('Phase %s skipped due to run_if returning falsey.',
glados-verma marked this conversation as resolved.
Show resolved Hide resolved
phase_desc.name)
return PhaseExecutionOutcome(phase_descriptor.PhaseResult.SKIP), None
return PhaseExecutionOutcome(phase_descriptor.PhaseResult.SKIP), None


override_result = None
with self.test_state.running_phase_context(phase_desc) as phase_state:
Expand Down
19 changes: 19 additions & 0 deletions test/core/phase_executor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@

import openhtf
from openhtf.core import phase_descriptor
from openhtf.core import test_record

def run_if_with_exception():
raise Exception("run_if_with_exception")

_tr = None
def final(tr):
global _tr
_tr = tr

class PhaseExecutorTest(unittest.TestCase):

Expand Down Expand Up @@ -54,3 +62,14 @@ def test_execute_phase_with_repeat_limit_max_exceeds_default_limit(self):
openhtf.PhaseOptions(repeat_limit=phase_descriptor.MAX_REPEAT_LIMIT),
expected_call_count=phase_descriptor.DEFAULT_REPEAT_LIMIT + 1,
)

def test_execute_phase_when_run_if_throws_exception(self):

@openhtf.PhaseOptions(run_if=run_if_with_exception)
def phase():
pass

test = openhtf.Test(phase)
test.add_output_callbacks(final)
test.execute()
self.assertEqual(_tr.outcome, test_record.Outcome.PASS)