Skip to content

Commit 5498b3e

Browse files
author
Yury Krasouski
authored
Merge pull request #49 from nberezin/bugfix-py2.7-compatibility
Bugfix for python2.7 compatibility issue #45
2 parents 29a817e + fa5cfda commit 5498b3e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

pytest_reportportal/rp_logging.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
from contextlib import contextmanager
44
from functools import wraps
5+
from six import PY2
56

67
from .service import PyTestService
78

@@ -22,7 +23,13 @@ def _log(self, level, msg, args,
2223
# exception on some versions of IronPython. We trap it here so that
2324
# IronPython can use logging.
2425
try:
25-
fn, lno, func, sinfo = self.findCaller(stack_info)
26+
if PY2:
27+
# In python2.7 findCaller() don't accept any parameters
28+
# and returns 3 elements
29+
fn, lno, func = self.findCaller()
30+
else:
31+
fn, lno, func, sinfo = self.findCaller(stack_info)
32+
2633
except ValueError: # pragma: no cover
2734
fn, lno, func = '(unknown file)', 0, '(unknown function)'
2835
else:
@@ -31,9 +38,14 @@ def _log(self, level, msg, args,
3138
if exc_info and not isinstance(exc_info, tuple):
3239
exc_info = sys.exc_info()
3340

34-
record = self.makeRecord(
35-
self.name, level, fn, lno, msg, args, exc_info, func, extra, sinfo
36-
)
41+
if PY2:
42+
# In python2.7 makeRecord() accepts everything but sinfo
43+
record = self.makeRecord(self.name, level, fn, lno, msg, args,
44+
exc_info, func, extra)
45+
else:
46+
record = self.makeRecord(self.name, level, fn, lno, msg, args,
47+
exc_info, func, extra, sinfo)
48+
3749
record.attachment = attachment
3850
self.handle(record)
3951

0 commit comments

Comments
 (0)