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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## [Unreleased]
### Fixed
- Microsecond logging for nested steps, by @HardNorth

## [5.7.3]
### Added
- Microseconds precision for timestamps, by @HardNorth

Expand Down
5 changes: 3 additions & 2 deletions reportportal_client/logs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
import logging
import sys
import threading
from datetime import datetime, timezone
from typing import TYPE_CHECKING, Any, Optional, Union
from urllib.parse import urlparse

# noinspection PyProtectedMember
from reportportal_client._internal.local import current, set_current
from reportportal_client.helpers import TYPICAL_MULTIPART_FOOTER_LENGTH, timestamp
from reportportal_client.helpers import TYPICAL_MULTIPART_FOOTER_LENGTH

if TYPE_CHECKING:
from reportportal_client.client import RP
Expand Down Expand Up @@ -195,7 +196,7 @@ def emit(self, record: logging.LogRecord) -> None:
set_current(rp_client)
if rp_client:
rp_client.log(
timestamp(),
datetime.now(tz=timezone.utc),
msg,
level=log_level,
attachment=record.__dict__.get("attachment", None),
Expand Down
19 changes: 13 additions & 6 deletions reportportal_client/steps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_my_nested_step():
pass

"""
from datetime import datetime, timezone
from functools import wraps
from typing import Any, Callable, Optional, TypeVar, Union

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

# noinspection PyProtectedMember
from reportportal_client._internal.local import current
from reportportal_client.helpers import get_function_params, timestamp
from reportportal_client.helpers import get_function_params

NESTED_STEP_ITEMS = (
"step",
Expand Down Expand Up @@ -88,7 +89,11 @@ def __init__(self, rp_client: "rp.RP"):
self.client = rp_client

def start_nested_step(
self, name: str, start_time: str, parameters: Optional[dict[str, Any]] = None, **_: dict[str, Any]
self,
name: str,
start_time: Union[str, datetime],
parameters: Optional[dict[str, Any]] = None,
**_: dict[str, Any],
) -> Union[Optional[str], Task[Optional[str]]]:
"""Start Nested Step on ReportPortal.

Expand All @@ -106,7 +111,7 @@ def start_nested_step(
def finish_nested_step(
self,
item_id: Union[str, Task[Optional[str]]],
end_time: str,
end_time: Union[str, datetime],
status: Optional[str] = None,
**_: dict[str, Any],
) -> Union[Optional[str], Task[Optional[str]]]:
Expand Down Expand Up @@ -151,11 +156,13 @@ def __enter__(self) -> None:
rp_client = self.client or current()
if not rp_client:
return
self.__item_id = rp_client.step_reporter.start_nested_step(self.name, timestamp(), parameters=self.params)
self.__item_id = rp_client.step_reporter.start_nested_step(
self.name, datetime.now(tz=timezone.utc), parameters=self.params
)
if self.params:
param_list = [str(key) + ": " + str(value) for key, value in sorted(self.params.items())]
param_str = "Parameters: " + "; ".join(param_list)
rp_client.log(timestamp(), param_str, level="INFO", item_id=self.__item_id)
rp_client.log(datetime.now(tz=timezone.utc), param_str, level="INFO", item_id=self.__item_id)

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

def __call__(self, *args, **kwargs):
"""Wrap and call a function reference.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from setuptools import find_packages, setup

__version__ = "5.7.3"
__version__ = "5.7.4"

TYPE_STUBS = ["*.pyi"]

Expand Down
6 changes: 3 additions & 3 deletions tests/logs/test_rp_log_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License
import re

# noinspection PyUnresolvedReferences
from datetime import datetime
from unittest import mock

# noinspection PyPackageRequirements
Expand Down Expand Up @@ -68,7 +67,8 @@ def test_emit_simple(mocked_handle):
call_args = mock_client.log.call_args[0]
call_kwargs = mock_client.log.call_args[1]

assert re.match("^[0-9]+$", call_args[0])
log_time = call_args[0]
assert isinstance(log_time, datetime)
assert test_message == call_args[1]
assert call_kwargs["level"] == "INFO"
assert not call_kwargs["attachment"]
Expand Down
Loading