From 68bbc623902e9410924cd8e783c928aaeb9790fb Mon Sep 17 00:00:00 2001 From: Chris Schance Date: Tue, 10 Apr 2018 22:03:14 -0600 Subject: [PATCH] Handle SystemExit with raises. --- devel-requirements.txt | 1 - pytest.ini | 2 -- src/hamcrest/core/core/raises.py | 2 +- tests/hamcrest_unit_test/core/raises_test.py | 9 +++++++++ 4 files changed, 10 insertions(+), 4 deletions(-) delete mode 100644 pytest.ini diff --git a/devel-requirements.txt b/devel-requirements.txt index 3cf58633..3265dcd0 100644 --- a/devel-requirements.txt +++ b/devel-requirements.txt @@ -1,4 +1,3 @@ six>=1.4 -tox>=1.8 pytest>=2.6 Sphinx>=1.2.2 diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 80c7b6a7..00000000 --- a/pytest.ini +++ /dev/null @@ -1,2 +0,0 @@ -[pytest] -addopts = --cov hamcrest --cov-report term-missing --no-cov-on-fail diff --git a/src/hamcrest/core/core/raises.py b/src/hamcrest/core/core/raises.py index 191f1df9..60c2d1c8 100644 --- a/src/hamcrest/core/core/raises.py +++ b/src/hamcrest/core/core/raises.py @@ -28,7 +28,7 @@ def _call_function(self, function): self.actual = None try: function() - except Exception: + except BaseException: self.actual = sys.exc_info()[1] if isinstance(self.actual, self.expected): diff --git a/tests/hamcrest_unit_test/core/raises_test.py b/tests/hamcrest_unit_test/core/raises_test.py index 02e8182b..ee87e45b 100644 --- a/tests/hamcrest_unit_test/core/raises_test.py +++ b/tests/hamcrest_unit_test/core/raises_test.py @@ -22,6 +22,10 @@ def raise_exception(*args, **kwargs): raise AssertionError(str(args) + str(kwargs)) +def raise_baseException(*args, **kwargs): + raise SystemExit(str(args) + str(kwargs)) + + class RaisesTest(MatcherTest): def testMatchesIfFunctionRaisesTheExactExceptionExpected(self): self.assert_matches('Right exception', @@ -38,6 +42,11 @@ def testMatchesIfFunctionRaisesASubclassOfTheExpectedException(self): raises(Exception), calling(raise_exception)) + def testMatchesIfFunctionRaisesASubclassOfTheExpectedBaseException(self): + self.assert_matches('Subclassed BasedException', + raises(BaseException), + calling(raise_baseException)) + def testDoesNotMatchIfFunctionDoesNotRaiseException(self): self.assert_does_not_match('No exception', raises(ValueError),