diff --git a/behave_reportportal/behave_agent.py b/behave_reportportal/behave_agent.py index 757c4c7..ba6b237 100644 --- a/behave_reportportal/behave_agent.py +++ b/behave_reportportal/behave_agent.py @@ -265,9 +265,9 @@ def _log_step_exception(self, step, item_id): ) ] if step.exception: - not_empty_args = self.not_empty_exception_args(step.exception) - if not_empty_args: - message.append(", ".join(not_empty_args)) + valuable_args = self.fetch_valuable_args(step.exception) + if valuable_args: + message.append(", ".join(valuable_args)) if step.error_message: message.append(step.error_message) @@ -281,9 +281,9 @@ def _log_step_exception(self, step, item_id): def _log_scenario_exception(self, scenario): message = ["Scenario '{}' finished with error.".format(scenario.name)] if scenario.exception: - not_empty_args = self.not_empty_exception_args(scenario.exception) - if not_empty_args: - message.append(", ".join(not_empty_args)) + valuable_args = self.fetch_valuable_args(scenario.exception) + if valuable_args: + message.append(", ".join(valuable_args)) if scenario.error_message: message.append(scenario.error_message) @@ -448,8 +448,7 @@ def convert_to_rp_status(behave_status): return "PASSED" @staticmethod - def not_empty_exception_args(exception): + def fetch_valuable_args(exception): """Return valuable exception args.""" - if exception.args: - if any(exception.args): - return [a for a in exception.args if a] + if exception.args and any(exception.args): + return [str(arg) for arg in exception.args if arg] diff --git a/tests/units/test_rp_agent.py b/tests/units/test_rp_agent.py index 8b86053..8d4d95f 100644 --- a/tests/units/test_rp_agent.py +++ b/tests/units/test_rp_agent.py @@ -824,9 +824,10 @@ def test_log_cleanup_scenario_based(mock_timestamp, config, scope, item_id): ((None, None), None), (("", None), None), (("A", "", None), ["A"]), + (("A", ["A", "B", "C"]), ["A", "['A', 'B', 'C']"]), ], ) -def test_not_empty_exception_args(args, exp): +def test_fetch_valuable_args(args, exp): exception = mock.Mock() exception.args = args - assert BehaveAgent.not_empty_exception_args(exception) == exp + assert BehaveAgent.fetch_valuable_args(exception) == exp