Skip to content

Commit

Permalink
fix done in XML report generation, to standardize outputs when runnin…
Browse files Browse the repository at this point in the history
…g in parallel and with a unique process
  • Loading branch information
anibalinn committed Sep 18, 2024
1 parent c256c00 commit a87d239
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
10 changes: 5 additions & 5 deletions behavex/outputs/jinja/xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@
{%- macro print_scenario(scenario) -%}
{%- set scenario_tags = scenario|get_scenario_tags-%}
{%- set is_muted = ('MUTE' in scenario_tags and scenario.status == 'failed')-%}
{%- set scenario_crashed = True if (scenario.status == 'failed' and not scenario.error_background and not scenario.error_step) else False -%}
{%- set errors_step = 0-%}
{%- for step in scenario.steps -%}
{%- set errors_step = errors_step + (0 if step.error_message else 1) -%}
{%- endfor -%}
<testcase time="{{ scenario.duration }}" name={{scenario.name|normalize|CIXC|quoteattr|safe}} status="{{ scenario.status if not is_muted else 'skipped'}}"
classname={{scenario.feature.name|normalize|CIXC|quoteattr|safe }}>
{%- set steps_with_exception = scenario.steps|get_list_exception_steps(scenario._background_steps) -%}
{%- set scenario_crashed = True if (scenario.status == 'failed' and steps_with_exception|length == 0) else False -%}
{%- if scenario_crashed and not is_muted -%}
<failure type=Exception message={{scenario.error_msg|get_error_message|CIXC|quoteattr|safe }}>
<![CDATA[ {{ scenario.error_msg }} ]]>
</failure>
<failure type=Exception message={{scenario.error_msg|get_error_message|CIXC|quoteattr|safe }}>
<![CDATA[ {{ scenario.error_msg }} ]]>
</failure>
{%- elif steps_with_exception and not is_muted -%}
{%- for step in steps_with_exception -%}
<failure type={{ step.exception.__class__.__name__ |normalize|CIXC|quoteattr|safe}} message={{step.exception.message|get_error_message|CIXC|quoteattr|safe }}>
<failure type={{ step.exception.__class__.__name__ |normalize|CIXC|quoteattr|safe}} message={{ step.exception|string|get_error_message|CIXC|quoteattr|safe}}>
<![CDATA[ Failing step: {{step|print_step|safe}} Location:{{step.filename|normalize|safe}}
{{step|get_lines_exception|safe}}
]]>
Expand Down
14 changes: 7 additions & 7 deletions behavex/outputs/jinja/xml_json.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{{'\n'}}
{%- endfor -%}
{%- endif -%}
{{ 16*' ' ~ step|print_step_json ~ '\n'}}
{{ 16*' ' ~ step|print_step_json|safe ~ '\n'}}
{%- endmacro -%}
{%- macro print_scenario(scenario) -%}
{%- set scenario_tags = scenario|get_scenario_tags-%}
Expand All @@ -30,13 +30,13 @@
classname={{scenario.feature|normalize|CIXC|quoteattr|safe }} >
{% set step_with_exception = scenario.error_step %}
{%- if scenario_crashed and not is_muted -%}
<failure type=Exception message={{scenario.error_msg|get_error_message|CIXC|quoteattr|safe }}>
<![CDATA[ {{ scenario.error_msg }} ]]>
</failure>
<failure type="Exception" message={{scenario.error_msg|get_error_message|CIXC|quoteattr|safe }}>
<![CDATA[ {{ scenario.error_msg }} ]]>
</failure>
{%- elif step_with_exception and not is_muted -%}
<failure message={{step_with_exception.error_msg|get_error_message|CIXC|quoteattr|safe }} type="AssertionError">
<![CDATA[ Failing step: {{step_with_exception|print_step_json|safe}} Location:{{step_with_exception.index}}
{{step_with_exception|safe}}
<failure type="AssertionError" message={{step_with_exception.error_msg|get_error_message|CIXC|quoteattr|safe }}>
<![CDATA[ Failing step: {{step_with_exception|print_step_json|safe}} Location:{{feature["filename"]}}
{{step_with_exception|get_lines_exception|safe}}
]]>
</failure>
{%- endif -%}
Expand Down
10 changes: 7 additions & 3 deletions behavex/outputs/jinja_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ def _print_step_json(step):


def get_lines_exception(step):
if step.exception:
if type(step) is dict:
return u'\n'.join(
[16 * u' ' + line for line in step['error_lines']]
).strip()
elif step.exception:
return u'\n'.join(
[16 * u' ' + line for line in traceback.format_tb(step.exc_traceback)]
).strip()
Expand Down Expand Up @@ -192,8 +196,8 @@ def _get_path_log(scenario):
return path_logs


def _quoteattr(string):
return "''" if not string else quoteattr(string)
def _quoteattr(string_to_quote):
return "''" if not string_to_quote else quoteattr(string_to_quote)


def _print_tag_xml(tags):
Expand Down
25 changes: 12 additions & 13 deletions behavex/outputs/report_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,23 +335,22 @@ def create_log_path(name, execution_retry=False):
return path


def get_error_message(message_error):
if not message_error:
def get_error_message(error_message):
if not error_message:
return u''
if isinstance(message_error, Exception):
if hasattr(message_error, 'message'):
if isinstance(error_message, Exception):
if hasattr(error_message, 'message'):
# noinspection PyBroadException
try:
message_error = traceback.format_tb(message_error.message)
error_message = traceback.format_tb(error_message.message)
except BaseException:
message_error = repr(message_error.message)
if hasattr(message_error, 'exc_traceback'):
message_error = traceback.format_tb(message_error.exc_traceback)
elif not isinstance(message_error, str):
message_error = repr(message_error)
return u'\n'.join(
[16 * u' ' + line for line in text(message_error).split('\n')]
).strip()
error_message = repr(error_message.message)
if hasattr(error_message, 'exc_traceback'):
error_message = traceback.format_tb(error_message.exc_traceback)
elif not isinstance(error_message, str):
error_message = repr(error_message)
formatted_error = u'\n'.join([16 * u' ' + line for line in text(error_message).split('\n')]).strip()
return formatted_error


def text(value, encoding=None, errors=None):
Expand Down

0 comments on commit a87d239

Please sign in to comment.