def setUp(self): super(BaseTestCase, self).setUp() # Ensure plugin cleanup is triggered last so that # test-specific cleanup has a chance to release references. self.addCleanup(self.cleanup_core_plugin) # Configure this first to ensure pm debugging support for setUp() if os.environ.get('OS_POST_MORTEM_DEBUG') in TRUE_STRING: self.addOnException(post_mortem_debug.exception_handler) if os.environ.get('OS_DEBUG') in TRUE_STRING: _level = logging.DEBUG else: _level = logging.INFO capture_logs = os.environ.get('OS_LOG_CAPTURE') in TRUE_STRING if not capture_logs: logging.basicConfig(format=LOG_FORMAT, level=_level) self.log_fixture = self.useFixture( fixtures.FakeLogger( format=LOG_FORMAT, level=_level, nuke_handlers=capture_logs, )) # suppress all but errors here self.useFixture( fixtures.FakeLogger( name='tacker.api.extensions', format=LOG_FORMAT, level=logging.ERROR, nuke_handlers=capture_logs, )) test_timeout = int(os.environ.get('OS_TEST_TIMEOUT', 0)) if test_timeout == -1: test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) # If someone does use tempfile directly, ensure that it's cleaned up self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.temp_dir = self.useFixture(fixtures.TempDir()).path cfg.CONF.set_override('state_path', self.temp_dir) self.setup_config() policy.init() self.addCleanup(policy.reset) self.addCleanup(mock.patch.stopall) self.addCleanup(CONF.reset) if os.environ.get('OS_STDOUT_CAPTURE') in TRUE_STRING: stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if os.environ.get('OS_STDERR_CAPTURE') in TRUE_STRING: stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) self.useFixture(fixtures.MonkeyPatch( 'tacker.common.exceptions.TackerException.use_fatal_exceptions', fake_use_fatal_exceptions)) self.useFixture(fixtures.MonkeyPatch( 'oslo_messaging.Notifier', fake_notifier.FakeNotifier)) self.messaging_conf = messaging_conffixture.ConfFixture(CONF) self.messaging_conf.transport_url = 'fake:/' self.messaging_conf.response_timeout = 15 self.useFixture(self.messaging_conf) self.addCleanup(n_rpc.clear_extra_exmods) n_rpc.add_extra_exmods('tacker.test') self.addCleanup(n_rpc.cleanup) n_rpc.init(CONF) if sys.version_info < (2, 7) and getattr(self, 'fmt', '') == 'xml': raise self.skipException('XML Testing Skipped in Py26')
def setUp(self): super(BaseTestCase, self).setUp() # Ensure plugin cleanup is triggered last so that # test-specific cleanup has a chance to release references. self.addCleanup(self.cleanup_core_plugin) # Configure this first to ensure pm debugging support for setUp() if os.environ.get('OS_POST_MORTEM_DEBUG') in TRUE_STRING: self.addOnException(post_mortem_debug.exception_handler) if os.environ.get('OS_DEBUG') in TRUE_STRING: _level = logging.DEBUG else: _level = logging.INFO capture_logs = os.environ.get('OS_LOG_CAPTURE') in TRUE_STRING if not capture_logs: logging.basicConfig(format=LOG_FORMAT, level=_level) self.log_fixture = self.useFixture( fixtures.FakeLogger( format=LOG_FORMAT, level=_level, nuke_handlers=capture_logs, )) # suppress all but errors here self.useFixture( fixtures.FakeLogger( name='tacker.api.extensions', format=LOG_FORMAT, level=logging.ERROR, nuke_handlers=capture_logs, )) test_timeout = int(os.environ.get('OS_TEST_TIMEOUT', 0)) if test_timeout == -1: test_timeout = 0 if test_timeout > 0: self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) # If someone does use tempfile directly, ensure that it's cleaned up self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) self.temp_dir = self.useFixture(fixtures.TempDir()).path cfg.CONF.set_override('state_path', self.temp_dir) self.setup_config() policy.init() self.addCleanup(policy.reset) self.addCleanup(mock.patch.stopall) self.addCleanup(CONF.reset) if os.environ.get('OS_STDOUT_CAPTURE') in TRUE_STRING: stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) if os.environ.get('OS_STDERR_CAPTURE') in TRUE_STRING: stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) self.useFixture( fixtures.MonkeyPatch( 'tacker.common.exceptions.TackerException.use_fatal_exceptions', fake_use_fatal_exceptions)) self.useFixture( fixtures.MonkeyPatch('oslo_messaging.Notifier', fake_notifier.FakeNotifier)) self.messaging_conf = messaging_conffixture.ConfFixture(CONF) self.messaging_conf.transport_url = 'fake:/' self.messaging_conf.response_timeout = 15 self.useFixture(self.messaging_conf) self.addCleanup(n_rpc.clear_extra_exmods) n_rpc.add_extra_exmods('tacker.test') self.addCleanup(n_rpc.cleanup) n_rpc.init(CONF) if sys.version_info < (2, 7) and getattr(self, 'fmt', '') == 'xml': raise self.skipException('XML Testing Skipped in Py26')