Skip to content

Commit f6c61f2

Browse files
author
Nick Berezin
committed
Fixing issue #45: adding python2.7 compatibility
1 parent 29a817e commit f6c61f2

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

pytest_reportportal/rp_logging.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,26 @@ def _log(self, level, msg, args,
1616
Low-level logging routine which creates a LogRecord and then calls
1717
all the handlers of this logger to handle the record.
1818
"""
19+
1920
sinfo = None
21+
p_version_flag = False
22+
23+
if (sys.version_info[0] < 3):
24+
# For python2.x compatibility
25+
p_version_flag = True
26+
2027
if logging._srcfile:
2128
# IronPython doesn't track Python frames, so findCaller raises an
2229
# exception on some versions of IronPython. We trap it here so that
2330
# IronPython can use logging.
2431
try:
25-
fn, lno, func, sinfo = self.findCaller(stack_info)
32+
if (p_version_flag):
33+
# In python2.x findCaller() don't accept any parameters
34+
# and returns 3 elements
35+
fn, lno, func = self.findCaller()
36+
else:
37+
fn, lno, func, sinfo = self.findCaller(stack_info)
38+
2639
except ValueError: # pragma: no cover
2740
fn, lno, func = '(unknown file)', 0, '(unknown function)'
2841
else:
@@ -31,9 +44,14 @@ def _log(self, level, msg, args,
3144
if exc_info and not isinstance(exc_info, tuple):
3245
exc_info = sys.exc_info()
3346

34-
record = self.makeRecord(
35-
self.name, level, fn, lno, msg, args, exc_info, func, extra, sinfo
36-
)
47+
if p_version_flag:
48+
# In python2.x makeRecord() accepts everything but sinfo
49+
record = self.makeRecord(self.name, level, fn, lno, msg, args,
50+
exc_info, func, extra)
51+
else:
52+
record = self.makeRecord(self.name, level, fn, lno, msg, args,
53+
exc_info, func, extra, sinfo)
54+
3755
record.attachment = attachment
3856
self.handle(record)
3957

0 commit comments

Comments
 (0)