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()
except KeyboardInterrupt:
raise
except:
except: # noqa
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))
except KeyboardInterrupt:
raise
except:
except: # noqa
try:
s = str(source[-1])
except KeyboardInterrupt:
raise
except:
except: # noqa
return 0
return 4 + (len(s) - len(s.lstrip()))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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