Skip to content

Commit 85d8ce6

Browse files
committed
Fix microsecond logging for nested steps
1 parent 0310eb2 commit 85d8ce6

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Fixed
5+
- Microsecond logging for nested steps, by @HardNorth
46

57
## [5.7.3]
68
### Added

reportportal_client/logs/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
import logging
1717
import sys
1818
import threading
19+
from datetime import datetime, timezone
1920
from typing import TYPE_CHECKING, Any, Optional, Union
2021
from urllib.parse import urlparse
2122

2223
# noinspection PyProtectedMember
2324
from reportportal_client._internal.local import current, set_current
24-
from reportportal_client.helpers import TYPICAL_MULTIPART_FOOTER_LENGTH, timestamp
25+
from reportportal_client.helpers import TYPICAL_MULTIPART_FOOTER_LENGTH
2526

2627
if TYPE_CHECKING:
2728
from reportportal_client.client import RP
@@ -195,7 +196,7 @@ def emit(self, record: logging.LogRecord) -> None:
195196
set_current(rp_client)
196197
if rp_client:
197198
rp_client.log(
198-
timestamp(),
199+
datetime.now(tz=timezone.utc),
199200
msg,
200201
level=log_level,
201202
attachment=record.__dict__.get("attachment", None),

reportportal_client/steps/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def test_my_nested_step():
4242
pass
4343
4444
"""
45+
from datetime import datetime, timezone
4546
from functools import wraps
4647
from typing import Any, Callable, Optional, TypeVar, Union
4748

@@ -52,7 +53,7 @@ def test_my_nested_step():
5253

5354
# noinspection PyProtectedMember
5455
from reportportal_client._internal.local import current
55-
from reportportal_client.helpers import get_function_params, timestamp
56+
from reportportal_client.helpers import get_function_params
5657

5758
NESTED_STEP_ITEMS = (
5859
"step",
@@ -88,7 +89,11 @@ def __init__(self, rp_client: "rp.RP"):
8889
self.client = rp_client
8990

9091
def start_nested_step(
91-
self, name: str, start_time: str, parameters: Optional[dict[str, Any]] = None, **_: dict[str, Any]
92+
self,
93+
name: str,
94+
start_time: Union[str, datetime],
95+
parameters: Optional[dict[str, Any]] = None,
96+
**_: dict[str, Any],
9297
) -> Union[Optional[str], Task[Optional[str]]]:
9398
"""Start Nested Step on ReportPortal.
9499
@@ -106,7 +111,7 @@ def start_nested_step(
106111
def finish_nested_step(
107112
self,
108113
item_id: Union[str, Task[Optional[str]]],
109-
end_time: str,
114+
end_time: Union[str, datetime],
110115
status: Optional[str] = None,
111116
**_: dict[str, Any],
112117
) -> Union[Optional[str], Task[Optional[str]]]:
@@ -151,11 +156,13 @@ def __enter__(self) -> None:
151156
rp_client = self.client or current()
152157
if not rp_client:
153158
return
154-
self.__item_id = rp_client.step_reporter.start_nested_step(self.name, timestamp(), parameters=self.params)
159+
self.__item_id = rp_client.step_reporter.start_nested_step(
160+
self.name, datetime.now(tz=timezone.utc), parameters=self.params
161+
)
155162
if self.params:
156163
param_list = [str(key) + ": " + str(value) for key, value in sorted(self.params.items())]
157164
param_str = "Parameters: " + "; ".join(param_list)
158-
rp_client.log(timestamp(), param_str, level="INFO", item_id=self.__item_id)
165+
rp_client.log(datetime.now(tz=timezone.utc), param_str, level="INFO", item_id=self.__item_id)
159166

160167
def __exit__(self, exc_type: type[BaseException], exc_val, exc_tb) -> None:
161168
"""Exit the runtime context related to this object."""
@@ -169,7 +176,7 @@ def __exit__(self, exc_type: type[BaseException], exc_val, exc_tb) -> None:
169176
step_status = self.status
170177
if any((exc_type, exc_val, exc_tb)):
171178
step_status = "FAILED"
172-
rp_client.step_reporter.finish_nested_step(self.__item_id, timestamp(), step_status)
179+
rp_client.step_reporter.finish_nested_step(self.__item_id, datetime.now(tz=timezone.utc), step_status)
173180

174181
def __call__(self, *args, **kwargs):
175182
"""Wrap and call a function reference.

0 commit comments

Comments
 (0)