From 9a02f942013ca7fdef596c80153f3e6f46a5da21 Mon Sep 17 00:00:00 2001 From: Dagan Sandler <1357456+dagansandler@users.noreply.github.com> Date: Sun, 4 Aug 2024 14:25:14 +0300 Subject: [PATCH] adding file location assertion to test_rp_logger, and fixing for 3.11 --- reportportal_client/logs/__init__.py | 2 ++ tests/logs/test_rp_logger.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/reportportal_client/logs/__init__.py b/reportportal_client/logs/__init__.py index c5c7a700..c699bdc7 100644 --- a/reportportal_client/logs/__init__.py +++ b/reportportal_client/logs/__init__.py @@ -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']) diff --git a/tests/logs/test_rp_logger.py b/tests/logs/test_rp_logger.py index a6beefb1..7ecaaa40 100644 --- a/tests/logs/test_rp_logger.py +++ b/tests/logs/test_rp_logger.py @@ -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') @@ -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__