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

## [Unreleased]
### Added
- Microseconds precision for timestamps, by @HardNorth
### Changed
- Client version updated on [5.7.4](https://github.com/reportportal/client-Python/releases/tag/5.7.4), by @HardNorth

## [5.1.1]
### Added
- Logging on Behave "error" status, by @HardNorth
### Changed
- Unknown statuses now handled as `FAILED`, by @HardNorth
Expand Down
45 changes: 26 additions & 19 deletions behave_reportportal/behave_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import os
import traceback
from collections import defaultdict
from datetime import datetime, timezone
from functools import wraps
from os import PathLike
from typing import Any, Callable, Optional, Union
Expand All @@ -34,7 +35,6 @@
gen_attributes,
get_launch_sys_attrs,
get_package_version,
timestamp,
)

from behave_reportportal.config import Config, LogLayout
Expand Down Expand Up @@ -140,7 +140,7 @@ def start_launch(self, _: Context, **kwargs: Any) -> None:
self._handle_lifecycle = False if self._rp.launch_uuid else True
self._launch_id = self._rp.launch_uuid or self._rp.start_launch(
name=self._cfg.launch_name,
start_time=timestamp(),
start_time=datetime.now(tz=timezone.utc),
attributes=self._get_launch_attributes(),
description=self._cfg.launch_description,
rerun=self._cfg.rerun,
Expand All @@ -152,7 +152,7 @@ def start_launch(self, _: Context, **kwargs: Any) -> None:
def finish_launch(self, _: Context, **kwargs: Any) -> None:
"""Finish launch in ReportPortal."""
if self._handle_lifecycle:
self._rp.finish_launch(end_time=timestamp(), **kwargs)
self._rp.finish_launch(end_time=datetime.now(tz=timezone.utc), **kwargs)
self._rp.close()

@check_rp_enabled
Expand All @@ -162,7 +162,7 @@ def start_feature(self, context: Context, feature: Feature, **kwargs: Any) -> No
feature.skip("Marked with @skip")
self._feature_id = self._rp.start_test_item(
name=feature.name,
start_time=timestamp(),
start_time=datetime.now(tz=timezone.utc),
item_type="SUITE",
description=self._item_description(context, feature),
code_ref=self._code_ref(feature),
Expand All @@ -180,7 +180,7 @@ def finish_feature(self, context: Context, feature: Feature, status: Optional[st
self._log_cleanups(context, "feature")
self._rp.finish_test_item(
item_id=self._feature_id,
end_time=timestamp(),
end_time=datetime.now(tz=timezone.utc),
status=status or convert_to_rp_status(feature.status.name),
**kwargs,
)
Expand All @@ -192,7 +192,7 @@ def start_scenario(self, context: Context, scenario: Scenario, **kwargs: Any) ->
scenario.skip("Marked with @skip")
self._scenario_id = self._rp.start_test_item(
name=scenario.name,
start_time=timestamp(),
start_time=datetime.now(tz=timezone.utc),
item_type="STEP",
parent_item_id=self._feature_id,
code_ref=self._code_ref(scenario),
Expand Down Expand Up @@ -223,7 +223,7 @@ def finish_scenario(
self._log_cleanups(context, "scenario")
self._rp.finish_test_item(
item_id=self._scenario_id,
end_time=timestamp(),
end_time=datetime.now(tz=timezone.utc),
status=status or rp_status,
**kwargs,
)
Expand All @@ -243,7 +243,7 @@ def start_step(self, _: Context, step: Step, **kwargs: Any) -> None:
step_content = self._build_step_content(step)
self._step_id = self._rp.start_test_item(
name=f"[{step.keyword}]: {step.name}",
start_time=timestamp(),
start_time=datetime.now(tz=timezone.utc),
item_type="STEP",
parent_item_id=self._scenario_id,
code_ref=self._code_ref(step),
Expand Down Expand Up @@ -307,10 +307,13 @@ def _log(
}
except OSError:
self._rp.log(
time=timestamp(), message=f"Attachment not found: {file_to_attach}", level="WARN", item_id=item_id
time=datetime.now(tz=timezone.utc),
message=f"Attachment not found: {file_to_attach}",
level="WARN",
item_id=item_id,
)
self._rp.log(
time=timestamp(),
time=datetime.now(tz=timezone.utc),
message=message,
level=level,
attachment=attachment,
Expand Down Expand Up @@ -344,7 +347,7 @@ def _finish_step_step_based(self, step: Step, status: Optional[str] = None, **kw
self._log_step_exception(step, self._step_id)
self._rp.finish_test_item(
item_id=self._step_id,
end_time=timestamp(),
end_time=datetime.now(tz=timezone.utc),
status=status or rp_status,
**kwargs,
)
Expand All @@ -354,7 +357,7 @@ def _finish_step_scenario_based(self, step: Step, **kwargs: Any) -> None:
step_content = self._build_step_content(step)
self._rp.log(
item_id=self._scenario_id,
time=timestamp(),
time=datetime.now(tz=timezone.utc),
message=f"[{step.keyword}]: {step.name}." + (f"\n\n{step_content}" if step_content else ""),
level="INFO",
**kwargs,
Expand Down Expand Up @@ -393,7 +396,7 @@ def _log_exception(self, initial_msg: str, exc_holder: BasicStatement, item_id:

self._rp.log(
item_id=item_id,
time=timestamp(),
time=datetime.now(tz=timezone.utc),
level="ERROR",
message="\n".join(message),
)
Expand All @@ -419,15 +422,17 @@ def _log_fixtures(
if self._cfg.log_layout is not LogLayout.SCENARIO:
self._step_id = self._rp.start_test_item(
name=msg,
start_time=timestamp(),
start_time=datetime.now(tz=timezone.utc),
item_type=item_type,
parent_item_id=parent_item_id,
has_stats=False if self._cfg.log_layout is LogLayout.NESTED else True,
)
self._rp.finish_test_item(item_id=self._step_id, end_time=timestamp(), status="PASSED")
self._rp.finish_test_item(
item_id=self._step_id, end_time=datetime.now(tz=timezone.utc), status="PASSED"
)
continue
self._rp.log(
timestamp(),
datetime.now(tz=timezone.utc),
msg,
level="INFO",
item_id=parent_item_id,
Expand All @@ -445,15 +450,17 @@ def _log_cleanups(self, context: Context, scope: str) -> None:
if self._cfg.log_layout is not LogLayout.SCENARIO:
self._step_id = self._rp.start_test_item(
name=msg,
start_time=timestamp(),
start_time=datetime.now(tz=timezone.utc),
item_type=item_type,
parent_item_id=item_id,
has_stats=False if self._cfg.log_layout is LogLayout.NESTED else True,
)
self._rp.finish_test_item(item_id=self._step_id, end_time=timestamp(), status="PASSED")
self._rp.finish_test_item(
item_id=self._step_id, end_time=datetime.now(tz=timezone.utc), status="PASSED"
)
continue
self._rp.log(
timestamp(),
datetime.now(tz=timezone.utc),
msg,
level="INFO",
item_id=item_id,
Expand Down
4 changes: 2 additions & 2 deletions behave_reportportal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Config(object):
log_batch_payload_limit: int
log_layout: LogLayout
launch_uuid_print: bool
launch_uuid_print_output: Optional[OutputType]
launch_uuid_print_output: OutputType
client_type: ClientType
http_timeout: Optional[Union[tuple[float, float], float]]

Expand Down Expand Up @@ -162,7 +162,7 @@ def __init__(
self.launch_uuid_print = to_bool(launch_uuid_print or "False")
launch_uuid_print_output_strip = launch_uuid_print_output.strip() if launch_uuid_print_output else ""
self.launch_uuid_print_output = (
OutputType[launch_uuid_print_output_strip.upper()] if launch_uuid_print_output_strip else None
OutputType[launch_uuid_print_output_strip.upper()] if launch_uuid_print_output_strip else OutputType.STDOUT
)
client_type_strip = client_type.strip() if client_type else ""
self.client_type = ClientType[client_type_strip.upper()] if client_type_strip else ClientType.SYNC
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
behave>=1.3.3,<2.0
prettytable
reportportal-client~=5.7.0
behave==1.3.3
prettytable>=3.6.0, <=3.17.0
reportportal-client==5.7.4
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.1"
__version__ = "5.1.2"


def read_file(fname):
Expand Down
6 changes: 3 additions & 3 deletions tests/units/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def test_read_config_default_values(mock_cp):
expect(cfg.rerun_of is None)
expect(cfg.enabled is True)
expect(cfg.launch_uuid_print is False)
expect(cfg.launch_uuid_print_output is None)
expect(cfg.launch_uuid_print_output is OutputType.STDOUT)
expect(cfg.client_type is ClientType.SYNC)
assert_expectations()

Expand Down Expand Up @@ -246,7 +246,7 @@ def test_launch_uuid_print(mock_cp):

cfg = read_config(mock_context)
assert cfg.launch_uuid_print
assert cfg.launch_uuid_print_output is None
assert cfg.launch_uuid_print_output is OutputType.STDOUT


@mock.patch("behave_reportportal.config.ConfigParser", autospec=True)
Expand Down Expand Up @@ -296,7 +296,7 @@ def test_no_launch_uuid_print(mock_cp):

cfg = read_config(mock_context)
assert not cfg.launch_uuid_print
assert cfg.launch_uuid_print_output is None
assert cfg.launch_uuid_print_output is OutputType.STDOUT


@pytest.mark.parametrize(
Expand Down
Loading
Loading