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:
parent
5ac01a56f5
commit
ab1c318d6d
@ -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))
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user