Allow to get current test case
Change-Id: Ia0796835f5f4bd7c9cf2f3f16f9402ad5bde0859
This commit is contained in:
parent
0d8b6d9430
commit
05c7a924be
|
@ -26,6 +26,7 @@ from tobiko.common import _operation
|
|||
from tobiko.common import _os
|
||||
from tobiko.common import _select
|
||||
from tobiko.common import _skip
|
||||
from tobiko.common import _testcase
|
||||
from tobiko.common import _utils
|
||||
|
||||
|
||||
|
@ -94,8 +95,12 @@ skip = _skip.skip
|
|||
skip_if = _skip.skip_if
|
||||
skip_unless = _skip.skip_unless
|
||||
|
||||
get_short_hostname = _utils.get_short_hostname
|
||||
get_test_case = _testcase.get_test_case
|
||||
pop_test_case = _testcase.pop_test_case
|
||||
push_test_case = _testcase.push_test_case
|
||||
TobikoTestCase = _testcase.TobikoTestCase
|
||||
|
||||
get_short_hostname = _utils.get_short_hostname
|
||||
|
||||
from tobiko import config # noqa
|
||||
config.init_config()
|
||||
|
|
|
@ -16,11 +16,11 @@ from __future__ import absolute_import
|
|||
import logging
|
||||
|
||||
from oslo_log import log
|
||||
import testtools
|
||||
from testtools import content
|
||||
|
||||
from tobiko.common import _detail
|
||||
from tobiko.common import _fixture
|
||||
from tobiko.common import _testcase
|
||||
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
@ -80,7 +80,7 @@ class CaptureLogHandler(logging.Handler):
|
|||
yield self.format(record) + '\n'
|
||||
|
||||
|
||||
class CaptureLogTest(testtools.TestCase):
|
||||
class CaptureLogTest(_testcase.TobikoTestCase):
|
||||
|
||||
capture_log_level = logging.DEBUG
|
||||
capture_log_logger = logging.root
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
# Copyright 2018 Red Hat
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from __future__ import absolute_import
|
||||
|
||||
|
||||
import testtools
|
||||
|
||||
from tobiko.common import _exception
|
||||
|
||||
|
||||
class TestCasesManager(object):
|
||||
|
||||
def __init__(self):
|
||||
self._test_cases = []
|
||||
|
||||
def get_test_case(self) -> testtools.TestCase:
|
||||
return self._test_cases[-1]
|
||||
|
||||
def pop_test_case(self) -> testtools.TestCase:
|
||||
return self._test_cases.pop()
|
||||
|
||||
def push_test_case(self, test_case: testtools.TestCase):
|
||||
_exception.check_valid_type(test_case, testtools.TestCase)
|
||||
self._test_cases.append(test_case)
|
||||
|
||||
|
||||
TEST_CASES = TestCasesManager()
|
||||
|
||||
|
||||
def push_test_case(test_case: testtools.TestCase, manager=TEST_CASES):
|
||||
return manager.push_test_case(test_case=test_case)
|
||||
|
||||
|
||||
def pop_test_case(manager=TEST_CASES):
|
||||
return manager.pop_test_case()
|
||||
|
||||
|
||||
def get_test_case(manager=TEST_CASES):
|
||||
return manager.get_test_case()
|
||||
|
||||
|
||||
class TobikoTestCase(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self._push_test_case()
|
||||
super(TobikoTestCase, self).setUp()
|
||||
|
||||
def _push_test_case(self):
|
||||
push_test_case(self)
|
||||
self.addCleanup(self._pop_test_case)
|
||||
|
||||
def _pop_test_case(self):
|
||||
self.assertIs(self, pop_test_case())
|
|
@ -228,6 +228,8 @@ def setup_tobiko_config(conf):
|
|||
tobiko.setup_fixture(HttpProxyFixture)
|
||||
if conf.logging.capture_log:
|
||||
monkey.patch(testtools, 'TestCase', tobiko.CaptureLogTest)
|
||||
else:
|
||||
monkey.patch(testtools, 'TestCase', tobiko.TobikoTestCase)
|
||||
|
||||
for module_name in CONFIG_MODULES:
|
||||
module = importlib.import_module(module_name)
|
||||
|
|
Loading…
Reference in New Issue