Fix linting E722: do not use bare except

This commit is contained in:
Bruno Oliveira 2017-11-04 13:21:34 -02:00
parent 03829fde8a
commit b11640c1eb
10 changed files with 15 additions and 18 deletions

View File

@ -250,7 +250,7 @@ class TracebackEntry(object):
line = str(self.statement).lstrip() line = str(self.statement).lstrip()
except KeyboardInterrupt: except KeyboardInterrupt:
raise raise
except: except: # noqa
line = "???" line = "???"
return " File %r:%d in %s\n %s\n" % (fn, self.lineno + 1, name, line) return " File %r:%d in %s\n %s\n" % (fn, self.lineno + 1, name, line)
@ -478,12 +478,12 @@ class FormattedExcinfo(object):
s = str(source.getstatement(len(source) - 1)) s = str(source.getstatement(len(source) - 1))
except KeyboardInterrupt: except KeyboardInterrupt:
raise raise
except: except: # noqa
try: try:
s = str(source[-1]) s = str(source[-1])
except KeyboardInterrupt: except KeyboardInterrupt:
raise raise
except: except: # noqa
return 0 return 0
return 4 + (len(s) - len(s.lstrip())) return 4 + (len(s) - len(s.lstrip()))

View File

@ -254,7 +254,7 @@ def findsource(obj):
sourcelines, lineno = py.std.inspect.findsource(obj) sourcelines, lineno = py.std.inspect.findsource(obj)
except py.builtin._sysex: except py.builtin._sysex:
raise raise
except: except: # noqa
return None, -1 return None, -1
source = Source() source = Source()
source.lines = [line.rstrip() for line in sourcelines] source.lines = [line.rstrip() for line in sourcelines]

View File

@ -210,7 +210,7 @@ class AssertionRewritingHook(object):
mod.__cached__ = pyc mod.__cached__ = pyc
mod.__loader__ = self mod.__loader__ = self
py.builtin.exec_(co, mod.__dict__) py.builtin.exec_(co, mod.__dict__)
except: except: # noqa
if name in sys.modules: if name in sys.modules:
del sys.modules[name] del sys.modules[name]
raise raise

View File

@ -749,7 +749,7 @@ class FixtureDef:
try: try:
func = self._finalizer.pop() func = self._finalizer.pop()
func() func()
except: except: # noqa
exceptions.append(sys.exc_info()) exceptions.append(sys.exc_info())
if exceptions: if exceptions:
e = exceptions[0] e = exceptions[0]

View File

@ -118,7 +118,7 @@ def wrap_session(config, doit):
excinfo.typename, excinfo.value.msg)) excinfo.typename, excinfo.value.msg))
config.hook.pytest_keyboard_interrupt(excinfo=excinfo) config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
session.exitstatus = EXIT_INTERRUPTED session.exitstatus = EXIT_INTERRUPTED
except: except: # noqa
excinfo = _pytest._code.ExceptionInfo() excinfo = _pytest._code.ExceptionInfo()
config.notify_exception(excinfo, config.option) config.notify_exception(excinfo, config.option)
session.exitstatus = EXIT_INTERNALERROR session.exitstatus = EXIT_INTERNALERROR
@ -375,7 +375,7 @@ class Node(object):
res = function() res = function()
except py.builtin._sysex: except py.builtin._sysex:
raise raise
except: except: # noqa
failure = sys.exc_info() failure = sys.exc_info()
setattr(self, exattrname, failure) setattr(self, exattrname, failure)
raise raise

View File

@ -84,7 +84,7 @@ class ApproxNumpy(ApproxBase):
try: try:
actual = np.asarray(actual) actual = np.asarray(actual)
except: except: # noqa
raise TypeError("cannot compare '{0}' to numpy.ndarray".format(actual)) raise TypeError("cannot compare '{0}' to numpy.ndarray".format(actual))
if actual.shape != self.expected.shape: if actual.shape != self.expected.shape:

View File

@ -197,7 +197,7 @@ class CallInfo:
except KeyboardInterrupt: except KeyboardInterrupt:
self.stop = time() self.stop = time()
raise raise
except: except: # noqa
self.excinfo = ExceptionInfo() self.excinfo = ExceptionInfo()
self.stop = time() self.stop = time()

View File

@ -115,7 +115,7 @@ class TestCaseFunction(Function):
fail("".join(values), pytrace=False) fail("".join(values), pytrace=False)
except (fail.Exception, KeyboardInterrupt): except (fail.Exception, KeyboardInterrupt):
raise raise
except: except: # noqa
fail("ERROR: Unknown Incompatible Exception " fail("ERROR: Unknown Incompatible Exception "
"representation:\n%r" % (rawexcinfo,), pytrace=False) "representation:\n%r" % (rawexcinfo,), pytrace=False)
except KeyboardInterrupt: except KeyboardInterrupt:

View File

@ -244,7 +244,7 @@ class TestTraceback_f_g_h(object):
def f(n): def f(n):
try: try:
do_stuff() do_stuff()
except: except: # noqa
reraise_me() reraise_me()
excinfo = pytest.raises(RuntimeError, f, 8) excinfo = pytest.raises(RuntimeError, f, 8)
@ -434,7 +434,7 @@ class TestFormattedExcinfo(object):
exec(source.compile()) exec(source.compile())
except KeyboardInterrupt: except KeyboardInterrupt:
raise raise
except: except: # noqa
return _pytest._code.ExceptionInfo() return _pytest._code.ExceptionInfo()
assert 0, "did not raise" assert 0, "did not raise"
@ -1217,7 +1217,7 @@ def test_exception_repr_extraction_error_on_recursion():
try: try:
a(numpy_like()) a(numpy_like())
except: except: # noqa
from _pytest._code.code import ExceptionInfo from _pytest._code.code import ExceptionInfo
from _pytest.pytester import LineMatcher from _pytest.pytester import LineMatcher
exc_info = ExceptionInfo() exc_info = ExceptionInfo()
@ -1241,7 +1241,7 @@ def test_no_recursion_index_on_recursion_error():
return getattr(self, '_' + attr) return getattr(self, '_' + attr)
RecursionDepthError().trigger RecursionDepthError().trigger
except: except: # noqa
from _pytest._code.code import ExceptionInfo from _pytest._code.code import ExceptionInfo
exc_info = ExceptionInfo() exc_info = ExceptionInfo()
if sys.version_info[:2] == (2, 6): if sys.version_info[:2] == (2, 6):

View File

@ -215,6 +215,3 @@ filterwarnings =
[flake8] [flake8]
max-line-length = 120 max-line-length = 120
exclude = _pytest/vendored_packages/pluggy.py exclude = _pytest/vendored_packages/pluggy.py
ignore=
# do not use bare except'
E722