Skip to content

Commit e581247

Browse files
authored
Merge pull request #59 from reportportal/develop
Release
2 parents 35e8153 + a7eeb7a commit e581247

4 files changed

Lines changed: 36 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
## [Unreleased]
44
### Added
5+
- Logging on Behave "error" status, by @HardNorth
6+
### Changed
7+
- Unknown statuses now handled as `FAILED`, by @HardNorth
8+
9+
## [5.1.0]
10+
### Added
511
- Official `Python 3.14` support, by @HardNorth
12+
- Behave "error" status support, by @hemanth-kumar-glean
613
### Changed
714
- Client version updated on [5.7.0](https://github.com/reportportal/client-Python/releases/tag/5.7.0), by @HardNorth
815
### Removed

behave_reportportal/behave_agent.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import mimetypes
1717
import os
1818
import traceback
19+
from collections import defaultdict
1920
from functools import wraps
2021
from os import PathLike
2122
from typing import Any, Callable, Optional, Union
@@ -39,6 +40,22 @@
3940
from behave_reportportal.config import Config, LogLayout
4041
from behave_reportportal.utils import Singleton
4142

43+
STATUS_MAPPINGS: dict[str, str] = defaultdict(lambda: "FAILED")
44+
STATUS_MAPPINGS["passed"] = "PASSED"
45+
STATUS_MAPPINGS["failed"] = "FAILED"
46+
STATUS_MAPPINGS["error"] = "ERROR"
47+
STATUS_MAPPINGS["skipped"] = "SKIPPED"
48+
49+
50+
def convert_to_rp_status(behave_status: str) -> str:
51+
"""
52+
Convert behave test result status to ReportPortal status.
53+
54+
:param behave_status: behave test result status
55+
:return: ReportPortal test result status
56+
"""
57+
return STATUS_MAPPINGS[behave_status]
58+
4259

4360
def check_rp_enabled(func: Callable) -> Callable:
4461
"""Verify is RP is enabled in config."""
@@ -164,7 +181,7 @@ def finish_feature(self, context: Context, feature: Feature, status: Optional[st
164181
self._rp.finish_test_item(
165182
item_id=self._feature_id,
166183
end_time=timestamp(),
167-
status=status or self.convert_to_rp_status(feature.status.name),
184+
status=status or convert_to_rp_status(feature.status.name),
168185
**kwargs,
169186
)
170187

@@ -199,14 +216,15 @@ def finish_scenario(
199216
"""Finish scenario in ReportPortal."""
200217
if scenario.tags and "skip" in scenario.tags:
201218
status = "SKIPPED"
202-
if scenario.status.name == "failed":
219+
rp_status = convert_to_rp_status(scenario.status.name)
220+
if rp_status == "FAILED":
203221
self._log_skipped_steps(context, scenario)
204222
self._log_scenario_exception(scenario)
205223
self._log_cleanups(context, "scenario")
206224
self._rp.finish_test_item(
207225
item_id=self._scenario_id,
208226
end_time=timestamp(),
209-
status=status or self.convert_to_rp_status(scenario.status.name),
227+
status=status or rp_status,
210228
**kwargs,
211229
)
212230
self._log_item_id = self._feature_id
@@ -321,12 +339,13 @@ def _build_step_content(step: Step) -> str:
321339
return txt
322340

323341
def _finish_step_step_based(self, step: Step, status: Optional[str] = None, **kwargs: Any) -> None:
324-
if step.status.name == "failed":
342+
rp_status = convert_to_rp_status(step.status.name)
343+
if rp_status == "FAILED":
325344
self._log_step_exception(step, self._step_id)
326345
self._rp.finish_test_item(
327346
item_id=self._step_id,
328347
end_time=timestamp(),
329-
status=status or self.convert_to_rp_status(step.status.name),
348+
status=status or rp_status,
330349
**kwargs,
331350
)
332351
self._log_item_id = self._scenario_id
@@ -340,7 +359,7 @@ def _finish_step_scenario_based(self, step: Step, **kwargs: Any) -> None:
340359
level="INFO",
341360
**kwargs,
342361
)
343-
if step.status.name == "failed":
362+
if convert_to_rp_status(step.status.name) == "FAILED":
344363
self._log_step_exception(step, self._scenario_id)
345364

346365
def _log_step_exception(self, step: Step, item_id: Optional[str]) -> None:
@@ -506,23 +525,3 @@ def _test_case_id(scenario: Scenario) -> Optional[Any]:
506525
return None
507526
return tc_id
508527
return None
509-
510-
@staticmethod
511-
def convert_to_rp_status(behave_status: str) -> str:
512-
"""
513-
Convert behave test result status to ReportPortal status.
514-
515-
:param behave_status: behave test result status
516-
:return: ReportPortal test result status
517-
"""
518-
if behave_status == "passed":
519-
return "PASSED"
520-
elif behave_status == "failed":
521-
return "FAILED"
522-
elif behave_status == "skipped":
523-
return "SKIPPED"
524-
elif behave_status == "error":
525-
return "FAILED"
526-
else:
527-
# todo define what to do
528-
return "PASSED"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from setuptools import setup
1919

20-
__version__ = "5.1.0"
20+
__version__ = "5.1.1"
2121

2222

2323
def read_file(fname):

tests/units/test_rp_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from reportportal_client import BatchedRPClient, RPClient, ThreadedRPClient
2424
from reportportal_client.logs import MAX_LOG_BATCH_PAYLOAD_SIZE
2525

26-
from behave_reportportal.behave_agent import BehaveAgent, create_rp_service
26+
from behave_reportportal.behave_agent import BehaveAgent, convert_to_rp_status, create_rp_service
2727
from behave_reportportal.config import Config, LogLayout
2828
from behave_reportportal.utils import Singleton
2929

@@ -52,11 +52,11 @@ def clean_instances():
5252
("passed", "PASSED"),
5353
("skipped", "SKIPPED"),
5454
("failed", "FAILED"),
55-
("xyz", "PASSED"),
55+
("xyz", "FAILED"),
5656
],
5757
)
5858
def test_convert_to_rp_status(status, expected):
59-
actual = BehaveAgent.convert_to_rp_status(status)
59+
actual = convert_to_rp_status(status)
6060
assert actual == expected, f"Incorrect status:\nActual: {actual}\nExpected:{expected}"
6161

6262

0 commit comments

Comments
 (0)