Skip to content

Commit 81c9a09

Browse files
authored
Merge pull request #270 from reportportal/develop
Release
2 parents 992be15 + b6fcaad commit 81c9a09

5 files changed

Lines changed: 24 additions & 12 deletions

File tree

CHANGELOG.md

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

33
## [Unreleased]
4+
### Fixed
5+
- Microsecond logging for nested steps, by @HardNorth
6+
7+
## [5.7.3]
48
### Added
59
- Microseconds precision for timestamps, by @HardNorth
610

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.

setup.py

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

55
from setuptools import find_packages, setup
66

7-
__version__ = "5.7.3"
7+
__version__ = "5.7.4"
88

99
TYPE_STUBS = ["*.pyi"]
1010

tests/logs/test_rp_log_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License
13-
import re
1413

15-
# noinspection PyUnresolvedReferences
14+
from datetime import datetime
1615
from unittest import mock
1716

1817
# noinspection PyPackageRequirements
@@ -68,7 +67,8 @@ def test_emit_simple(mocked_handle):
6867
call_args = mock_client.log.call_args[0]
6968
call_kwargs = mock_client.log.call_args[1]
7069

71-
assert re.match("^[0-9]+$", call_args[0])
70+
log_time = call_args[0]
71+
assert isinstance(log_time, datetime)
7272
assert test_message == call_args[1]
7373
assert call_kwargs["level"] == "INFO"
7474
assert not call_kwargs["attachment"]

0 commit comments

Comments
 (0)