Skip to content

Commit

Permalink
Full refactoring to manage unexpected exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
anibalinn committed Aug 21, 2024
1 parent c4e4629 commit feef671
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 85 deletions.
15 changes: 12 additions & 3 deletions behavex/outputs/jinja/main.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@
<!-- scenario_hash has been forced to be a string -->
{%- set scenario_hash = scenario_hash|string -%}
{%- set scenario_tags = scenario|get_scenario_tags -%}
{%- set scenario_background_failed = True if (scenario.error_background and (scenario.status == 'failed' or scenario.status == 'untested')) else False -%}
{%- set scenario_crashed = True if (scenario.status == 'failed' and not scenario.error_background and not scenario.error_step) else False -%}
<tr class="table_row_commons behavex_letter feature-scenario text-center"
data-scenario-tags="{{ scenario_tags|to_string_list }}">
<td class="text-left grey-behavex">
Expand Down Expand Up @@ -334,8 +336,15 @@
{%- endif -%}
{%- endfor -%}
</ul>
{% endif %}
{%- if scenario.error_background and (scenario.status == 'failed' or scenario.status == 'untested' )-%}
{%- endif -%}
{%- if scenario_crashed -%}
<br>
<p style="padding-left:12px;padding-top:15px;padding-bottom:2px" data-div-id_hash="{{ scenario.id_hash }}">
<span class="glyphicon glyphicon-warning-sign"></span>
<b>{{ scenario.error_msg }}</b>
<br>
<hr class='line-behavex-background'>
{%- elif scenario_background_failed -%}
<br>
<p style="padding-left:12px;padding-top:15px;padding-bottom:2px" data-div-id_hash="{{ scenario.id_hash }}">
<span class="glyphicon glyphicon-warning-sign"></span>
Expand Down Expand Up @@ -402,7 +411,7 @@
{%- set path_log_scenario = path_log_scenario|string -%}
{%- set path_img_scenario = path_join(path_log, scenario_hash, 'images.html')-%}
{%- set path_img_scenario = path_img_scenario|string -%}
{%- if path_log_scenario|path_exist_in_output -%}
{%- if path_log_scenario|path_exist_in_output and not scenario_crashed -%}
<a href="{{ path_log_scenario|replace(get_env('OUTPUT'), '.')|normalize_path|urlencode }}"
charset="utf-8" class="btn btn-info btn-xs" title="View Test Logs"
data-log>
Expand Down
7 changes: 6 additions & 1 deletion behavex/outputs/jinja/xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@
{%- 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) -%}
{%- if steps_with_exception and 'MUTE' not in scenario_tags -%}
{%- if scenario_crashed -%}
<failure type=Exception message={{scenario.error_msg|get_error_message|CIXC|quoteattr|safe }}>
<![CDATA[ {{ scenario.error_msg }} ]]>
</failure>
{%- elif steps_with_exception and 'MUTE' not in scenario_tags -%}
{%- 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 }}>
<![CDATA[ Failing step: {{step|print_step|safe}} Location:{{step.filename|normalize|safe}}
Expand Down
7 changes: 6 additions & 1 deletion behavex/outputs/jinja/xml_json.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@
{%- 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 -%}
<testcase time="{{ scenario.duration }}" name={{scenario.name|normalize|CIXC|quoteattr|safe}} status="{{ 'skipped' if is_muted else scenario.status }}"
classname={{scenario.feature|normalize|CIXC|quoteattr|safe }} >
{% set step_with_exception = scenario.error_step %}
{%- if step_with_exception and 'MUTE' not in scenario_tags -%}
{%- if scenario_crashed -%}
<failure type=Exception message={{scenario.error_msg|get_error_message|CIXC|quoteattr|safe }}>
<![CDATA[ {{ scenario.error_msg }} ]]>
</failure>
{%- elif step_with_exception and 'MUTE' not in scenario_tags -%}
<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}}
Expand Down
1 change: 0 additions & 1 deletion behavex/outputs/report_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def get_status(scenario_):
for scenario in scenarios
if get_status(scenario) == Status.failed or get_status(scenario) == Status.untested
]

muted = [
scenario
for scenario in scenarios
Expand Down
2 changes: 1 addition & 1 deletion behavex/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _print_progress_bar(self, new_line=False):
elapsed_time = time.time() - self.start_time
elapsed_formatted = time.strftime("%M:%S", time.gmtime(elapsed_time))
progress_bar_content = f"\r{prefix}{percent:.0f}%|{bar}| {self.current_iteration}/{self.total} [{elapsed_formatted}]\r"
if self.print_in_new_lines or new_line:
if self.print_in_new_lines or new_line or percent == 100:
print(progress_bar_content)
else:
sys.stdout.write(progress_bar_content)
Expand Down
Loading

0 comments on commit feef671

Please sign in to comment.