Skip to content

Commit

Permalink
Handle SystemExit with raises.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Schance committed Oct 30, 2018
1 parent 75b4f7b commit 68bbc62
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 0 additions & 1 deletion devel-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
six>=1.4
tox>=1.8
pytest>=2.6
Sphinx>=1.2.2
2 changes: 0 additions & 2 deletions pytest.ini

This file was deleted.

2 changes: 1 addition & 1 deletion src/hamcrest/core/core/raises.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions tests/hamcrest_unit_test/core/raises_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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),
Expand Down

0 comments on commit 68bbc62

Please sign in to comment.