Fix #2343: Replace version checks by constants.
This way they do not have to be recomputed at runtime.
This commit is contained in:
parent
47a2a77cb4
commit
7d4ac14a31
|
@ -2,13 +2,14 @@ import sys
|
||||||
from inspect import CO_VARARGS, CO_VARKEYWORDS
|
from inspect import CO_VARARGS, CO_VARKEYWORDS
|
||||||
import re
|
import re
|
||||||
from weakref import ref
|
from weakref import ref
|
||||||
|
from _pytest.compat import _PY2, _PY3, PY35
|
||||||
|
|
||||||
import py
|
import py
|
||||||
builtin_repr = repr
|
builtin_repr = repr
|
||||||
|
|
||||||
reprlib = py.builtin._tryimport('repr', 'reprlib')
|
reprlib = py.builtin._tryimport('repr', 'reprlib')
|
||||||
|
|
||||||
if sys.version_info[0] >= 3:
|
if _PY3:
|
||||||
from traceback import format_exception_only
|
from traceback import format_exception_only
|
||||||
else:
|
else:
|
||||||
from ._py2traceback import format_exception_only
|
from ._py2traceback import format_exception_only
|
||||||
|
@ -352,7 +353,7 @@ class ExceptionInfo(object):
|
||||||
help for navigating the traceback.
|
help for navigating the traceback.
|
||||||
"""
|
"""
|
||||||
_striptext = ''
|
_striptext = ''
|
||||||
_assert_start_repr = "AssertionError(u\'assert " if sys.version_info[0] < 3 else "AssertionError(\'assert "
|
_assert_start_repr = "AssertionError(u\'assert " if _PY2 else "AssertionError(\'assert "
|
||||||
|
|
||||||
def __init__(self, tup=None, exprinfo=None):
|
def __init__(self, tup=None, exprinfo=None):
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
|
@ -617,7 +618,7 @@ class FormattedExcinfo(object):
|
||||||
|
|
||||||
|
|
||||||
def repr_excinfo(self, excinfo):
|
def repr_excinfo(self, excinfo):
|
||||||
if sys.version_info[0] < 3:
|
if _PY2:
|
||||||
reprtraceback = self.repr_traceback(excinfo)
|
reprtraceback = self.repr_traceback(excinfo)
|
||||||
reprcrash = excinfo._getreprcrash()
|
reprcrash = excinfo._getreprcrash()
|
||||||
|
|
||||||
|
@ -654,7 +655,7 @@ class FormattedExcinfo(object):
|
||||||
class TerminalRepr(object):
|
class TerminalRepr(object):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = self.__unicode__()
|
s = self.__unicode__()
|
||||||
if sys.version_info[0] < 3:
|
if _PY2:
|
||||||
s = s.encode('utf-8')
|
s = s.encode('utf-8')
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
@ -850,7 +851,7 @@ def getrawcode(obj, trycall=True):
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info[:2] >= (3, 5): # RecursionError introduced in 3.5
|
if PY35: # RecursionError introduced in 3.5
|
||||||
def is_recursion_error(excinfo):
|
def is_recursion_error(excinfo):
|
||||||
return excinfo.errisinstance(RecursionError) # noqa
|
return excinfo.errisinstance(RecursionError) # noqa
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -27,6 +27,7 @@ _PY2 = not _PY3
|
||||||
NoneType = type(None)
|
NoneType = type(None)
|
||||||
NOTSET = object()
|
NOTSET = object()
|
||||||
|
|
||||||
|
PY35 = sys.version_info[:2] >= (3, 5)
|
||||||
PY36 = sys.version_info[:2] >= (3, 6)
|
PY36 = sys.version_info[:2] >= (3, 6)
|
||||||
MODULE_NOT_FOUND_ERROR = 'ModuleNotFoundError' if PY36 else 'ImportError'
|
MODULE_NOT_FOUND_ERROR = 'ModuleNotFoundError' if PY36 else 'ImportError'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue