Skip to content

Instantly share code, notes, and snippets.

@danodonovan
Last active March 6, 2017 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danodonovan/042e1c74ea76cbea39b42f5c8733ede0 to your computer and use it in GitHub Desktop.
Save danodonovan/042e1c74ea76cbea39b42f5c8733ede0 to your computer and use it in GitHub Desktop.
PyHamcrest not catching SystemExit exception
import sys
import unittest
from hamcrest import assert_that, calling, raises
import pytest
def call_exit():
sys.exit()
class TestUnittest(unittest.TestCase):
def test_exits(self):
with self.assertRaises(SystemExit):
call_exit()
def test_pytest():
with pytest.raises(SystemExit):
call_exit()
def test_hamcrest():
assert_that(calling(call_exit), raises(SystemExit))
@danodonovan
Copy link
Author

Results in test test_hamcrest tests failing (and others passing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment