Skip to content

Fix #2343: Replace version checks by constants. #2359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions _pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
from inspect import CO_VARARGS, CO_VARKEYWORDS
import re
from weakref import ref
from _pytest.compat import _PY2, _PY3, PY35

import py
builtin_repr = repr

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

if sys.version_info[0] >= 3:
if _PY3:
from traceback import format_exception_only
else:
from ._py2traceback import format_exception_only
Expand Down Expand Up @@ -352,7 +353,7 @@ class ExceptionInfo(object):
help for navigating the traceback.
"""
_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):
import _pytest._code
Expand Down Expand Up @@ -617,7 +618,7 @@ def repr_traceback(self, excinfo):


def repr_excinfo(self, excinfo):
if sys.version_info[0] < 3:
if _PY2:
reprtraceback = self.repr_traceback(excinfo)
reprcrash = excinfo._getreprcrash()

Expand Down Expand Up @@ -654,7 +655,7 @@ def repr_excinfo(self, excinfo):
class TerminalRepr(object):
def __str__(self):
s = self.__unicode__()
if sys.version_info[0] < 3:
if _PY2:
s = s.encode('utf-8')
return s

Expand Down Expand Up @@ -850,7 +851,7 @@ def getrawcode(obj, trycall=True):
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):
return excinfo.errisinstance(RecursionError) # noqa
else:
Expand Down
1 change: 1 addition & 0 deletions _pytest/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
NoneType = type(None)
NOTSET = object()

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

Expand Down