Skip to content

Commit a10282e

Browse files
committed
Log line reference fix for Python 3.11
1 parent e0633d8 commit a10282e

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
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+
- Log line reference for Python 3.11, by @HardNorth
46
### Changed
57
- Client version updated on [5.4.0](https://github.com/reportportal/client-Python/releases/tag/5.4.0), by @HardNorth
68

pytest_reportportal/rp_logging.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""RPLogger class for low-level logging in tests."""
22

3+
import sys
34
import logging
45
import threading
56
from contextlib import contextmanager
@@ -108,7 +109,17 @@ def _log(self, *args, **kwargs):
108109
if attachment is not None:
109110
kwargs.setdefault('extra', {}).update(
110111
{'attachment': attachment})
111-
return original_func(self, *args, **kwargs)
112+
# Python 3.11 start catches stack frames in wrappers,
113+
# so add additional stack level skip to not show it
114+
if sys.version_info >= (3, 11):
115+
my_kwargs = kwargs.copy()
116+
if 'stacklevel' in kwargs:
117+
my_kwargs['stacklevel'] = my_kwargs['stacklevel'] + 1
118+
else:
119+
my_kwargs['stacklevel'] = 2
120+
return original_func(self, *args, **my_kwargs)
121+
else:
122+
return original_func(self, *args, **kwargs)
112123

113124
return _log
114125

tests/integration/test_config_handling.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,7 @@ def test_rp_log_format(mock_client_init):
131131
expect(mock_client.log.call_count == 1)
132132
message = mock_client.log.call_args_list[0][0][1]
133133
expect(len(message) > 0)
134-
if sys.version_info < (3, 11):
135-
expect(message == '(examples.test_rp_logging) ' + LOG_MESSAGE +
136-
' (test_rp_logging.py:24)')
137-
else:
138-
# FIXME: implement stacktrace preserve solution for Python 3.11
139-
warnings.warn('FIXME: implement stacktrace preserve solution for Python 3.11', RuntimeWarning)
140-
expect(message == '(examples.test_rp_logging) ' + LOG_MESSAGE +
141-
' (rp_logging.py:111)')
134+
expect(message == f'(examples.test_rp_logging) {LOG_MESSAGE} (test_rp_logging.py:24)')
142135
assert_expectations()
143136

144137

0 commit comments

Comments
 (0)