|
2 | 2 | from inspect import CO_VARARGS, CO_VARKEYWORDS
|
3 | 3 | import re
|
4 | 4 | from weakref import ref
|
| 5 | +from _pytest.compat import _PY2, _PY3, PY35 |
5 | 6 |
|
6 | 7 | import py
|
7 | 8 | builtin_repr = repr
|
8 | 9 |
|
9 | 10 | reprlib = py.builtin._tryimport('repr', 'reprlib')
|
10 | 11 |
|
11 |
| -if sys.version_info[0] >= 3: |
| 12 | +if _PY3: |
12 | 13 | from traceback import format_exception_only
|
13 | 14 | else:
|
14 | 15 | from ._py2traceback import format_exception_only
|
@@ -352,7 +353,7 @@ class ExceptionInfo(object):
|
352 | 353 | help for navigating the traceback.
|
353 | 354 | """
|
354 | 355 | _striptext = ''
|
355 |
| - _assert_start_repr = "AssertionError(u\'assert " if sys.version_info[0] < 3 else "AssertionError(\'assert " |
| 356 | + _assert_start_repr = "AssertionError(u\'assert " if _PY2 else "AssertionError(\'assert " |
356 | 357 |
|
357 | 358 | def __init__(self, tup=None, exprinfo=None):
|
358 | 359 | import _pytest._code
|
@@ -617,7 +618,7 @@ def repr_traceback(self, excinfo):
|
617 | 618 |
|
618 | 619 |
|
619 | 620 | def repr_excinfo(self, excinfo):
|
620 |
| - if sys.version_info[0] < 3: |
| 621 | + if _PY2: |
621 | 622 | reprtraceback = self.repr_traceback(excinfo)
|
622 | 623 | reprcrash = excinfo._getreprcrash()
|
623 | 624 |
|
@@ -654,7 +655,7 @@ def repr_excinfo(self, excinfo):
|
654 | 655 | class TerminalRepr(object):
|
655 | 656 | def __str__(self):
|
656 | 657 | s = self.__unicode__()
|
657 |
| - if sys.version_info[0] < 3: |
| 658 | + if _PY2: |
658 | 659 | s = s.encode('utf-8')
|
659 | 660 | return s
|
660 | 661 |
|
@@ -850,7 +851,7 @@ def getrawcode(obj, trycall=True):
|
850 | 851 | return obj
|
851 | 852 |
|
852 | 853 |
|
853 |
| -if sys.version_info[:2] >= (3, 5): # RecursionError introduced in 3.5 |
| 854 | +if PY35: # RecursionError introduced in 3.5 |
854 | 855 | def is_recursion_error(excinfo):
|
855 | 856 | return excinfo.errisinstance(RecursionError) # noqa
|
856 | 857 | else:
|
|
0 commit comments