Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 19 additions & 12 deletions testit-adapter-pytest/src/testit_adapter_pytest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from traceback import format_exception_only

from _pytest.mark import Mark
from testit_python_commons.models.link import Link
from testit_python_commons.models.test_result import TestResult
from testit_python_commons.models.test_result_with_all_fixture_step_results_model import TestResultWithAllFixtureStepResults
Expand Down Expand Up @@ -36,18 +37,24 @@ def form_test(item) -> ExecutableTest:
)

if item.own_markers:
for mark in item.own_markers:
if mark.name == 'skip' or mark.name == 'skipif':
executable_test.outcome = 'Skipped'
if mark.args:
executable_test.message = mark.args[0]
if mark.kwargs and 'reason' in mark.kwargs:
executable_test.message = mark.kwargs['reason']
if mark.name == 'xfail':
if mark.args:
executable_test.message = mark.args[0]
if mark.kwargs and 'reason' in mark.kwargs:
executable_test.message = mark.kwargs['reason']
executable_test = __set_outcome_and_message_from_markers(executable_test, item.own_markers)

return executable_test


def __set_outcome_and_message_from_markers(executable_test: ExecutableTest, markers: List[Mark]) -> ExecutableTest:
for marker in markers:
if marker.name in ('skip', 'skipif'):
executable_test.outcome = 'Skipped'
if marker.name in ('skip', 'skipif', 'xfail'):
if len(marker.args) == 1 and isinstance(marker.args, str):
executable_test.message = marker.args[0]

condition_in_args = marker.args and marker.args[0]
condition_in_kwargs = marker.kwargs and 'condition' in marker.kwargs and marker.kwargs['condition']

if (condition_in_kwargs or condition_in_args) and 'reason' in marker.kwargs:
executable_test.message = marker.kwargs['reason']

return executable_test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ def end_test(self, name, attributes):
self.active_test.outcome = STATUSES[attributes['status']]
self.active_test.started_on = convert_time(attributes['starttime'])
self.active_test.completed_on = convert_time(attributes['endtime'])
if not self.active_test.message:
if self.active_test.outcome == 'Failed':
for step in (self.active_test.setUpResults + self.active_test.stepResults +
self.active_test.tearDownResults):
if step.outcome == 'Failed':
self.active_test.message = f"Failed on step: '{step.title}'"
break
if not self.active_test.message and self.active_test.outcome == 'Failed':
for step in (self.active_test.setUpResults + self.active_test.stepResults +
self.active_test.tearDownResults):
if step.outcome == 'Failed':
self.active_test.message = f"Failed on step: '{step.title}'"
break
self.active_test.traces = attributes['message']
self.active_test.duration = attributes['elapsedtime']
self.adapter_manager.write_test(
Expand Down