Setup required fixture by default
Change-Id: If8f79aaa90a97bbf469b0bb1f7d88d4d50e9dcb7
This commit is contained in:
parent
4233ae5ddf
commit
680f9c9ec2
@ -473,9 +473,10 @@ class FixtureProperty(property):
|
|||||||
|
|
||||||
class RequiredFixtureProperty(object):
|
class RequiredFixtureProperty(object):
|
||||||
|
|
||||||
def __init__(self, fixture, **params):
|
def __init__(self, fixture, setup=True, **params):
|
||||||
self.fixture = fixture
|
self.fixture = fixture
|
||||||
self.fixture_params = params
|
self.fixture_params = params
|
||||||
|
self.setup = setup
|
||||||
|
|
||||||
def __get__(self, instance, _):
|
def __get__(self, instance, _):
|
||||||
if instance is None:
|
if instance is None:
|
||||||
@ -484,7 +485,15 @@ class RequiredFixtureProperty(object):
|
|||||||
return self.get_fixture(instance)
|
return self.get_fixture(instance)
|
||||||
|
|
||||||
def get_fixture(self, _instance):
|
def get_fixture(self, _instance):
|
||||||
return get_fixture(self.fixture, **self.fixture_params)
|
fixture = get_fixture(self.fixture, **self.fixture_params)
|
||||||
|
if self.setup:
|
||||||
|
setup_fixture(fixture)
|
||||||
|
if (hasattr(_instance, 'addCleanup') and
|
||||||
|
hasattr(_instance, 'getDetails')):
|
||||||
|
_instance.addCleanup(_detail.gather_details,
|
||||||
|
fixture.getDetails(),
|
||||||
|
_instance.getDetails())
|
||||||
|
return fixture
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __tobiko_required_fixtures__(self):
|
def __tobiko_required_fixtures__(self):
|
||||||
|
@ -32,7 +32,8 @@ CONF = config.CONF
|
|||||||
|
|
||||||
class SSHClientFixtureTest(unit.TobikoUnitTest):
|
class SSHClientFixtureTest(unit.TobikoUnitTest):
|
||||||
|
|
||||||
fixture = tobiko.required_fixture(ssh.SSHClientFixture)
|
fixture = tobiko.required_fixture(ssh.SSHClientFixture,
|
||||||
|
setup=False)
|
||||||
|
|
||||||
expected_host = None
|
expected_host = None
|
||||||
expected_proxy_client = None
|
expected_proxy_client = None
|
||||||
|
@ -316,80 +316,76 @@ class MyRequiredFixture(MyBaseFixture):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MyRequiredSetupFixture(MyBaseFixture):
|
class RequiredFixtureTest(unit.TobikoUnitTest):
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ListRequiredFixtureTest(unit.TobikoUnitTest):
|
|
||||||
|
|
||||||
required_fixture = tobiko.required_fixture(MyRequiredFixture)
|
required_fixture = tobiko.required_fixture(MyRequiredFixture)
|
||||||
required_setup_fixture = tobiko.required_setup_fixture(
|
required_fixture_no_setup = tobiko.required_fixture(
|
||||||
MyRequiredSetupFixture)
|
MyRequiredFixture, setup=False)
|
||||||
|
|
||||||
def test_with_module(self):
|
def test_list_required_fixtures_with_module(self):
|
||||||
module = sys.modules[__name__]
|
module = sys.modules[__name__]
|
||||||
result = tobiko.list_required_fixtures([module])
|
result = tobiko.list_required_fixtures([module])
|
||||||
self.assertEqual([], result)
|
self.assertEqual([], result)
|
||||||
|
|
||||||
def test_with_module_name(self):
|
def test_list_required_fixtures_with_module_name(self):
|
||||||
result = tobiko.list_required_fixtures([__name__])
|
result = tobiko.list_required_fixtures([__name__])
|
||||||
self.assertEqual([], result)
|
self.assertEqual([], result)
|
||||||
|
|
||||||
def test_with_testcase_type(self):
|
def test_list_required_fixtures_with_testcase_type(self):
|
||||||
result = tobiko.list_required_fixtures([ListRequiredFixtureTest])
|
result = tobiko.list_required_fixtures([RequiredFixtureTest])
|
||||||
self.assertEqual([canonical_name(MyRequiredFixture),
|
self.assertEqual([canonical_name(MyRequiredFixture)], result)
|
||||||
canonical_name(MyRequiredSetupFixture)], result)
|
|
||||||
|
|
||||||
def test_with_testcase_name(self):
|
def test_list_required_fixtures_with_testcase_name(self):
|
||||||
result = tobiko.list_required_fixtures(
|
result = tobiko.list_required_fixtures(
|
||||||
[canonical_name(ListRequiredFixtureTest)])
|
[canonical_name(RequiredFixtureTest)])
|
||||||
self.assertEqual([canonical_name(MyRequiredFixture),
|
self.assertEqual([canonical_name(MyRequiredFixture)], result)
|
||||||
canonical_name(MyRequiredSetupFixture)], result)
|
|
||||||
|
|
||||||
def test_with_unbound_method(self, fixture=MyFixture, fixture2=MyFixture2):
|
def test_list_required_fixtures_with_unbound_method(
|
||||||
|
self, fixture=MyFixture, fixture2=MyFixture2):
|
||||||
|
cls = RequiredFixtureTest
|
||||||
result = tobiko.list_required_fixtures(
|
result = tobiko.list_required_fixtures(
|
||||||
[ListRequiredFixtureTest.test_with_unbound_method])
|
[cls.test_list_required_fixtures_with_unbound_method])
|
||||||
self.assertEqual([canonical_name(fixture),
|
self.assertEqual([canonical_name(fixture),
|
||||||
canonical_name(fixture2),
|
canonical_name(fixture2),
|
||||||
canonical_name(MyRequiredFixture),
|
canonical_name(MyRequiredFixture)], result)
|
||||||
canonical_name(MyRequiredSetupFixture)], result)
|
|
||||||
|
|
||||||
def test_with_bound_method(self, fixture=MyFixture, fixture2=MyFixture2):
|
def test_list_required_fixtures_with_bound_method(
|
||||||
result = tobiko.list_required_fixtures([self.test_with_bound_method])
|
self, fixture=MyFixture, fixture2=MyFixture2):
|
||||||
|
result = tobiko.list_required_fixtures([
|
||||||
|
self.test_list_required_fixtures_with_bound_method])
|
||||||
self.assertEqual([canonical_name(fixture),
|
self.assertEqual([canonical_name(fixture),
|
||||||
canonical_name(fixture2),
|
canonical_name(fixture2),
|
||||||
canonical_name(MyRequiredFixture),
|
canonical_name(MyRequiredFixture)], result)
|
||||||
canonical_name(MyRequiredSetupFixture)], result)
|
|
||||||
|
|
||||||
def test_with_method_name(self, fixture=MyFixture, fixture2=MyFixture2):
|
def test_list_required_fixtures_with_method_name(
|
||||||
|
self, fixture=MyFixture, fixture2=MyFixture2):
|
||||||
result = tobiko.list_required_fixtures([self.id()])
|
result = tobiko.list_required_fixtures([self.id()])
|
||||||
self.assertEqual([canonical_name(fixture),
|
self.assertEqual([canonical_name(fixture),
|
||||||
canonical_name(fixture2),
|
canonical_name(fixture2),
|
||||||
canonical_name(MyRequiredFixture),
|
canonical_name(MyRequiredFixture)], result)
|
||||||
canonical_name(MyRequiredSetupFixture)], result)
|
|
||||||
|
|
||||||
def test_with_fixture_name(self):
|
def test_list_required_fixtures_with_fixture_name(self):
|
||||||
result = tobiko.list_required_fixtures([canonical_name(MyFixture)])
|
result = tobiko.list_required_fixtures([canonical_name(MyFixture)])
|
||||||
self.assertEqual([canonical_name(MyFixture)], result)
|
self.assertEqual([canonical_name(MyFixture)], result)
|
||||||
|
|
||||||
def test_with_fixture(self):
|
def test_list_required_fixtures_with_fixture(self):
|
||||||
result = tobiko.list_required_fixtures([MyFixture()])
|
result = tobiko.list_required_fixtures([MyFixture()])
|
||||||
self.assertEqual([canonical_name(MyFixture)], result)
|
self.assertEqual([canonical_name(MyFixture)], result)
|
||||||
|
|
||||||
def test_with_fixture_type(self):
|
def test__list_required_fixtures_with_fixture_type(self):
|
||||||
result = tobiko.list_required_fixtures([MyFixture])
|
result = tobiko.list_required_fixtures([MyFixture])
|
||||||
self.assertEqual([canonical_name(MyFixture)], result)
|
self.assertEqual([canonical_name(MyFixture)], result)
|
||||||
|
|
||||||
def test_required_fixture_property(self):
|
def test_required_fixture_with_instance(self):
|
||||||
fixture = self.required_fixture
|
fixture = self.required_fixture
|
||||||
self.assertIsInstance(fixture, MyRequiredFixture)
|
self.assertIsInstance(fixture, MyRequiredFixture)
|
||||||
fixture.setup_fixture.assert_not_called()
|
fixture.setup_fixture.assert_called()
|
||||||
fixture.cleanup_fixture.assert_not_called()
|
fixture.cleanup_fixture.assert_not_called()
|
||||||
|
|
||||||
def test_required_setup_fixture_property(self):
|
def test_required_fixture_with_no_setup(self):
|
||||||
fixture = self.required_setup_fixture
|
fixture = self.required_fixture_no_setup
|
||||||
self.assertIsInstance(fixture, MyRequiredSetupFixture)
|
self.assertIsInstance(fixture, MyRequiredFixture)
|
||||||
fixture.setup_fixture.assert_called_once_with()
|
fixture.setup_fixture.assert_not_called()
|
||||||
fixture.cleanup_fixture.assert_not_called()
|
fixture.cleanup_fixture.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user