Skip to content

Commit

Permalink
Merge pull request #233 from dagansandler/fix_python311_stacklevel_lo…
Browse files Browse the repository at this point in the history
…gging

Fixing Record pathnames are incorrect on python3.11
  • Loading branch information
HardNorth authored Sep 2, 2024
2 parents f1ce5f7 + 9a02f94 commit 1a2729f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions reportportal_client/logs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def _log(self, level, msg, args, exc_info=None, extra=None,
# exception on some versions of IronPython. We trap it here so that
# IronPython can use logging.
try:
if sys.version_info >= (3, 11):
kwargs.setdefault('stacklevel', 2)
if 'stacklevel' in kwargs:
fn, lno, func, sinfo = \
self.findCaller(stack_info, kwargs['stacklevel'])
Expand Down
2 changes: 2 additions & 0 deletions tests/logs/test_rp_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_record_make(logger_handler):
logger.info('test_log')
record = verify_record(logger_handler)
assert not getattr(record, 'attachment')
assert record.pathname == __file__


@mock.patch('reportportal_client.logs.logging.Logger.handle')
Expand Down Expand Up @@ -86,3 +87,4 @@ def test_stacklevel_record_make(logger_handler):
stack_info=inspect.stack(), stacklevel=2)
record = verify_record(logger_handler)
assert record.stack_info.endswith("logger.error('test_log', exc_info=RuntimeError('test'),")
assert record.pathname == __file__

0 comments on commit 1a2729f

Please sign in to comment.