Skip to content

Commit

Permalink
Update user properties on teardown (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
juhhov authored Jun 2, 2022
1 parent 2d1f282 commit e306116
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pytest_opentmi/OpenTmiReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ def _update_teardown_result(self, report):
# update result with updated last_result
self.results[-1] = last_result

def _update_user_properties(self, report, result=None):
if report.user_properties:
if not result:
result = self.results[-1]
if not 'properties' in result.execution.profiling:
result.execution.profiling['properties'] = {}
for (key, value) in report.user_properties:
result.execution.profiling['properties'][key] = value

@staticmethod
def _get_tcid(report):
return report.head_line.rstrip("[]")
Expand Down Expand Up @@ -188,10 +197,7 @@ def _new_result(self, report):
result.execution.sut.tag = tag
result.job.id = os.environ.get('BUILD_TAG', str(uuid.uuid1()))
result.campaign = os.environ.get('JOB_NAME', "")
if report.user_properties:
result.execution.profiling['properties'] = {}
for (key, value) in report.user_properties:
result.execution.profiling['properties'][key] = value
self._update_user_properties(report=report, result=result)
if report.keywords:
result.execution.profiling['keywords'] = []
for key in report.keywords:
Expand Down Expand Up @@ -335,6 +341,7 @@ def pytest_runtest_logreport(self, report):
elif report.skipped:
self._append_skipped(report)
elif report.when == 'teardown':
self._update_user_properties(report=report)
# Update test result only if teardown result != passed
if not report.passed:
self._update_teardown_result(report)
Expand Down

0 comments on commit e306116

Please sign in to comment.