From b11640c1eb27a170e6390b4b39be8b06e23f3a5a Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 4 Nov 2017 13:21:34 -0200 Subject: [PATCH] Fix linting E722: do not use bare except --- _pytest/_code/code.py | 6 +++--- _pytest/_code/source.py | 2 +- _pytest/assertion/rewrite.py | 2 +- _pytest/fixtures.py | 2 +- _pytest/main.py | 4 ++-- _pytest/python_api.py | 2 +- _pytest/runner.py | 2 +- _pytest/unittest.py | 2 +- testing/code/test_excinfo.py | 8 ++++---- tox.ini | 3 --- 10 files changed, 15 insertions(+), 18 deletions(-) diff --git a/_pytest/_code/code.py b/_pytest/_code/code.py index 34655abeb..f3b7eedfc 100644 --- a/_pytest/_code/code.py +++ b/_pytest/_code/code.py @@ -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())) diff --git a/_pytest/_code/source.py b/_pytest/_code/source.py index 96c88451b..fc4171264 100644 --- a/_pytest/_code/source.py +++ b/_pytest/_code/source.py @@ -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] diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index c3966340a..d48b6648f 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -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 diff --git a/_pytest/fixtures.py b/_pytest/fixtures.py index 6c9f251f8..926396407 100644 --- a/_pytest/fixtures.py +++ b/_pytest/fixtures.py @@ -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] diff --git a/_pytest/main.py b/_pytest/main.py index 91083c85f..3bd4022b7 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -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 diff --git a/_pytest/python_api.py b/_pytest/python_api.py index a3cf1c8cb..80684c131 100644 --- a/_pytest/python_api.py +++ b/_pytest/python_api.py @@ -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: diff --git a/_pytest/runner.py b/_pytest/runner.py index ed58aceec..b22fa684f 100644 --- a/_pytest/runner.py +++ b/_pytest/runner.py @@ -197,7 +197,7 @@ class CallInfo: except KeyboardInterrupt: self.stop = time() raise - except: + except: # noqa self.excinfo = ExceptionInfo() self.stop = time() diff --git a/_pytest/unittest.py b/_pytest/unittest.py index 939e45206..52c9813e8 100644 --- a/_pytest/unittest.py +++ b/_pytest/unittest.py @@ -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: diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index 35ab1cfcc..263d053b5 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -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): diff --git a/tox.ini b/tox.ini index 1071324bc..48913bd7b 100644 --- a/tox.ini +++ b/tox.ini @@ -215,6 +215,3 @@ filterwarnings = [flake8] max-line-length = 120 exclude = _pytest/vendored_packages/pluggy.py -ignore= - # do not use bare except' - E722