Skip to content

Commit 7dfdfa5

Browse files
authored
Merge pull request #2359 from pytest-dev/fix-2343
Fix #2343: Replace version checks by constants.
2 parents 47a2a77 + 7d4ac14 commit 7dfdfa5

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

_pytest/_code/code.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
from inspect import CO_VARARGS, CO_VARKEYWORDS
33
import re
44
from weakref import ref
5+
from _pytest.compat import _PY2, _PY3, PY35
56

67
import py
78
builtin_repr = repr
89

910
reprlib = py.builtin._tryimport('repr', 'reprlib')
1011

11-
if sys.version_info[0] >= 3:
12+
if _PY3:
1213
from traceback import format_exception_only
1314
else:
1415
from ._py2traceback import format_exception_only
@@ -352,7 +353,7 @@ class ExceptionInfo(object):
352353
help for navigating the traceback.
353354
"""
354355
_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 "
356357

357358
def __init__(self, tup=None, exprinfo=None):
358359
import _pytest._code
@@ -617,7 +618,7 @@ def repr_traceback(self, excinfo):
617618

618619

619620
def repr_excinfo(self, excinfo):
620-
if sys.version_info[0] < 3:
621+
if _PY2:
621622
reprtraceback = self.repr_traceback(excinfo)
622623
reprcrash = excinfo._getreprcrash()
623624

@@ -654,7 +655,7 @@ def repr_excinfo(self, excinfo):
654655
class TerminalRepr(object):
655656
def __str__(self):
656657
s = self.__unicode__()
657-
if sys.version_info[0] < 3:
658+
if _PY2:
658659
s = s.encode('utf-8')
659660
return s
660661

@@ -850,7 +851,7 @@ def getrawcode(obj, trycall=True):
850851
return obj
851852

852853

853-
if sys.version_info[:2] >= (3, 5): # RecursionError introduced in 3.5
854+
if PY35: # RecursionError introduced in 3.5
854855
def is_recursion_error(excinfo):
855856
return excinfo.errisinstance(RecursionError) # noqa
856857
else:

_pytest/compat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
NoneType = type(None)
2828
NOTSET = object()
2929

30+
PY35 = sys.version_info[:2] >= (3, 5)
3031
PY36 = sys.version_info[:2] >= (3, 6)
3132
MODULE_NOT_FOUND_ERROR = 'ModuleNotFoundError' if PY36 else 'ImportError'
3233

0 commit comments

Comments
 (0)