Skip to content
Open
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
47 changes: 27 additions & 20 deletions src/etos_test_runner/lib/testrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,30 +245,37 @@ def execute(self): # pylint:disable=too-many-branches,disable=too-many-statemen
description = None
executed = False
test_framework_exit_codes = []
outcome = None
try:
with Workspace(self.log_area) as workspace:
self.logger.info("Start IUT monitoring.")
self.iut_monitoring.start_monitoring()
self.logger.info("Starting test executor.")
result, test_framework_exit_codes = self.run_tests(workspace)
executed = True
self.logger.info("Stop IUT monitoring.")
self.iut_monitoring.stop_monitoring()
except Exception as exception: # pylint:disable=broad-except
result = False
executed = False
description = str(exception)
raise
try:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need another level of nesting?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inner try/finally is needed so that on_test_suite_finished and outcome computation run inside the with Workspace block, before Workspace.__exit__ triggers artifact upload.

Without the inner try/finally, if tests raise an exception, the with block would exit immediately (uploading artifacts), and we'd never call the plugin handlers in time. The inner finally guarantees the plugin handlers run even on exception, but still before the workspace context manager cleans up and uploads.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I would rather we create a method. I dont like the sight-line with three levels of nesting

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

self.logger.info("Start IUT monitoring.")
self.iut_monitoring.start_monitoring()
self.logger.info("Starting test executor.")
result, test_framework_exit_codes = self.run_tests(workspace)
executed = True
self.logger.info("Stop IUT monitoring.")
self.iut_monitoring.stop_monitoring()
except Exception as exception: # pylint:disable=broad-except
result = False
executed = False
description = str(exception)
raise
finally:
if self.iut_monitoring.monitoring:
self.logger.info("Stop IUT monitoring.")
self.iut_monitoring.stop_monitoring()
self.logger.info("Figure out test outcome.")
outcome = self.outcome(result, executed, description, test_framework_exit_codes)
pprint(outcome)
self.logger.info("Call on_test_suite_finished plugin handlers.")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

self._test_suite_finished(self.config.get("name"), outcome)
finally:
if self.iut_monitoring.monitoring:
self.logger.info("Stop IUT monitoring.")
self.iut_monitoring.stop_monitoring()
self.logger.info("Figure out test outcome.")
outcome = self.outcome(result, executed, description, test_framework_exit_codes)
pprint(outcome)

if outcome is None:
self.logger.info("Figure out test outcome.")
outcome = self.outcome(result, executed, description, test_framework_exit_codes)
pprint(outcome)
self.logger.info("Send test suite finished event.")
self._test_suite_finished(self.config.get("name"), outcome)
test_suite_finished = self.etos.events.send_test_suite_finished(
test_suite_started,
links={"CONTEXT": self.etos.config.get("context")},
Expand Down
Loading