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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

## [Unreleased]
### Added
- Logging on Behave "error" status, by @HardNorth
### Changed
- Unknown statuses now handled as `FAILED`, by @HardNorth

## [5.1.0]
### Added
- Official `Python 3.14` support, by @HardNorth
- Behave "error" status support, by @hemanth-kumar-glean
### Changed
- Client version updated on [5.7.0](https://github.com/reportportal/client-Python/releases/tag/5.7.0), by @HardNorth
### Removed
Expand Down
51 changes: 25 additions & 26 deletions behave_reportportal/behave_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import mimetypes
import os
import traceback
from collections import defaultdict
from functools import wraps
from os import PathLike
from typing import Any, Callable, Optional, Union
Expand All @@ -39,6 +40,22 @@
from behave_reportportal.config import Config, LogLayout
from behave_reportportal.utils import Singleton

STATUS_MAPPINGS: dict[str, str] = defaultdict(lambda: "FAILED")
STATUS_MAPPINGS["passed"] = "PASSED"
STATUS_MAPPINGS["failed"] = "FAILED"
STATUS_MAPPINGS["error"] = "ERROR"
STATUS_MAPPINGS["skipped"] = "SKIPPED"


def convert_to_rp_status(behave_status: str) -> str:
"""
Convert behave test result status to ReportPortal status.

:param behave_status: behave test result status
:return: ReportPortal test result status
"""
return STATUS_MAPPINGS[behave_status]


def check_rp_enabled(func: Callable) -> Callable:
"""Verify is RP is enabled in config."""
Expand Down Expand Up @@ -164,7 +181,7 @@ def finish_feature(self, context: Context, feature: Feature, status: Optional[st
self._rp.finish_test_item(
item_id=self._feature_id,
end_time=timestamp(),
status=status or self.convert_to_rp_status(feature.status.name),
status=status or convert_to_rp_status(feature.status.name),
**kwargs,
)

Expand Down Expand Up @@ -199,14 +216,15 @@ def finish_scenario(
"""Finish scenario in ReportPortal."""
if scenario.tags and "skip" in scenario.tags:
status = "SKIPPED"
if scenario.status.name == "failed":
rp_status = convert_to_rp_status(scenario.status.name)
if rp_status == "FAILED":
self._log_skipped_steps(context, scenario)
self._log_scenario_exception(scenario)
self._log_cleanups(context, "scenario")
self._rp.finish_test_item(
item_id=self._scenario_id,
end_time=timestamp(),
status=status or self.convert_to_rp_status(scenario.status.name),
status=status or rp_status,
**kwargs,
)
self._log_item_id = self._feature_id
Expand Down Expand Up @@ -321,12 +339,13 @@ def _build_step_content(step: Step) -> str:
return txt

def _finish_step_step_based(self, step: Step, status: Optional[str] = None, **kwargs: Any) -> None:
if step.status.name == "failed":
rp_status = convert_to_rp_status(step.status.name)
if rp_status == "FAILED":
self._log_step_exception(step, self._step_id)
self._rp.finish_test_item(
item_id=self._step_id,
end_time=timestamp(),
status=status or self.convert_to_rp_status(step.status.name),
status=status or rp_status,
**kwargs,
)
self._log_item_id = self._scenario_id
Expand All @@ -340,7 +359,7 @@ def _finish_step_scenario_based(self, step: Step, **kwargs: Any) -> None:
level="INFO",
**kwargs,
)
if step.status.name == "failed":
if convert_to_rp_status(step.status.name) == "FAILED":
self._log_step_exception(step, self._scenario_id)

def _log_step_exception(self, step: Step, item_id: Optional[str]) -> None:
Expand Down Expand Up @@ -506,23 +525,3 @@ def _test_case_id(scenario: Scenario) -> Optional[Any]:
return None
return tc_id
return None

@staticmethod
def convert_to_rp_status(behave_status: str) -> str:
"""
Convert behave test result status to ReportPortal status.

:param behave_status: behave test result status
:return: ReportPortal test result status
"""
if behave_status == "passed":
return "PASSED"
elif behave_status == "failed":
return "FAILED"
elif behave_status == "skipped":
return "SKIPPED"
elif behave_status == "error":
return "FAILED"
else:
# todo define what to do
return "PASSED"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from setuptools import setup

__version__ = "5.1.0"
__version__ = "5.1.1"


def read_file(fname):
Expand Down
6 changes: 3 additions & 3 deletions tests/units/test_rp_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from reportportal_client import BatchedRPClient, RPClient, ThreadedRPClient
from reportportal_client.logs import MAX_LOG_BATCH_PAYLOAD_SIZE

from behave_reportportal.behave_agent import BehaveAgent, create_rp_service
from behave_reportportal.behave_agent import BehaveAgent, convert_to_rp_status, create_rp_service
from behave_reportportal.config import Config, LogLayout
from behave_reportportal.utils import Singleton

Expand Down Expand Up @@ -52,11 +52,11 @@ def clean_instances():
("passed", "PASSED"),
("skipped", "SKIPPED"),
("failed", "FAILED"),
("xyz", "PASSED"),
("xyz", "FAILED"),
],
)
def test_convert_to_rp_status(status, expected):
actual = BehaveAgent.convert_to_rp_status(status)
actual = convert_to_rp_status(status)
assert actual == expected, f"Incorrect status:\nActual: {actual}\nExpected:{expected}"


Expand Down