Moved sys.exit mocking into BaseTestClass

The BaseTestClass will be used as the base or all tests so mocking that
should happen for all tests belongs here.

Change-Id: Ia73812fd6c17a79060a3088c509cf82225d6707f
This commit is contained in:
David Stanek 2015-03-09 21:17:34 +00:00
parent 5ac01a56f5
commit ab1c318d6d
2 changed files with 10 additions and 3 deletions

View File

@ -275,6 +275,11 @@ class BaseTestCase(oslotest.BaseTestCase):
eliminating unnecessary work.
"""
def setUp(self):
super(BaseTestCase, self).setUp()
self.useFixture(mockpatch.PatchObject(sys, 'exit',
side_effect=UnexpectedExit))
def cleanup_instance(self, *names):
"""Create a function suitable for use with self.addCleanup.
@ -380,8 +385,6 @@ class TestCase(BaseTestCase):
self.addCleanup(CONF.reset)
self.useFixture(mockpatch.PatchObject(sys, 'exit',
side_effect=UnexpectedExit))
self.useFixture(mockpatch.PatchObject(logging.Handler, 'handleError',
side_effect=BadLog))
self.config_fixture = self.useFixture(config_fixture.Config(CONF))

View File

@ -25,12 +25,16 @@ from keystone.tests import unit as tests
LOG = log.getLogger(__name__)
class TestTestCase(tests.TestCase):
class BaseTestTestCase(tests.BaseTestCase):
def test_unexpected_exit(self):
# if a test calls sys.exit it raises rather than exiting.
self.assertThat(lambda: sys.exit(),
matchers.raises(tests.UnexpectedExit))
class TestTestCase(tests.TestCase):
def test_bad_log(self):
# If the arguments are invalid for the string in a log it raises an
# exception during testing.