Skip to content

Commit

Permalink
Merge pull request #165 from iamkenos/fix/strip-ansi-codes-on-report-…
Browse files Browse the repository at this point in the history
…output

fix: strip ansi codes on report output
  • Loading branch information
hrcorval authored Oct 10, 2024
2 parents 26c799b + 13e1e62 commit fd3c375
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion behavex/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from behavex.conf_mgr import get_env, get_param
from behavex.global_vars import global_vars
from behavex.outputs import report_json, report_xml
from behavex.outputs.report_utils import create_log_path
from behavex.outputs.report_utils import create_log_path, strip_ansi_codes
from behavex.utils import (LOGGING_CFG, create_custom_log_when_called,
get_autoretry_attempts, get_logging_level,
get_scenario_tags, get_scenarios_instances)
Expand Down Expand Up @@ -197,6 +197,7 @@ def _add_log_handler(log_path):
)
log_level = get_logging_level()
logging.getLogger().setLevel(log_level)
file_handler.addFilter(lambda record: setattr(record, 'msg', strip_ansi_codes(str(record.msg))) or True)
file_handler.setFormatter(_get_log_formatter())
logging.getLogger().addHandler(file_handler)
return file_handler
Expand Down
8 changes: 6 additions & 2 deletions behavex/outputs/report_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ def gather_steps(features):


def gather_errors(scenario, retrieve_step_name=False):
error_msg = list(map(lambda line: strip_ansi_codes(line), scenario['error_msg']))
if retrieve_step_name:
return scenario['error_msg'], scenario['error_lines'], scenario['error_step']
return error_msg, scenario['error_lines'], scenario['error_step']
else:
return scenario['error_msg'], scenario['error_lines']
return error_msg, scenario['error_lines']


def pretty_print_time(seconds_float, sec_decimals=1):
Expand Down Expand Up @@ -449,3 +450,6 @@ def get_environment_details():
environment_details_raw_data = os.getenv('ENVIRONMENT_DETAILS', None)
environment_details = environment_details_raw_data.split(',') if environment_details_raw_data else []
return environment_details

def strip_ansi_codes(from_str: str):
return re.sub(r'\x1B\[[0-?9;]*[mGJK]', '', from_str)

0 comments on commit fd3c375

Please sign in to comment.