cinder.test module¶
Base classes for our unit tests.
Allows overriding of CONF for use of fakes, and some black magic for inline callbacks.
-
class
Database
(db_api, db_migrate, sql_connection)¶ Bases:
fixtures.fixture.Fixture
-
setUp
()¶ Prepare the Fixture for use.
This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.
After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).
- Raises
MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.
- Returns
None.
- Changed in 1.3
The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.
- Changed in 1.3.1
BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.
-
-
class
ModelsObjectComparatorMixin
¶ Bases:
object
-
class
RPCAPITestCase
(*args, **kwargs)¶ Bases:
cinder.test.TestCase
,cinder.test.ModelsObjectComparatorMixin
-
setUp
()¶ Run before each test method to initialize test environment.
-
-
class
TestCase
(*args, **kwargs)¶ Bases:
testtools.testcase.TestCase
Test case base class for all unit tests.
-
MOCK_TOOZ
= True¶
-
MOCK_WORKER
= True¶
-
POLICY_PATH
= 'cinder/tests/unit/policy.json'¶
-
RESOURCE_FILTER_PATH
= 'etc/cinder/resource_filters.json'¶
-
assertFalse
(x, *args, **kwargs)¶ Assert that value is False.
- If original behavior is required we will need to do:
assertFalse(bool(result))
-
assertTrue
(x, *args, **kwargs)¶ Assert that value is True.
- If original behavior is required we will need to do:
assertTrue(bool(result))
-
assert_notify_called
(mock_notify, calls, any_order=False)¶
-
flags
(**kw)¶ Override CONF variables for a test.
-
mock_object
(obj, attr_name, *args, **kwargs)¶ Use python mock to mock an object attribute
Mocks the specified objects attribute with the given value. Automatically performs ‘addCleanup’ for the mock.
-
override_config
(name, override, group=None)¶ Cleanly override CONF variables.
-
patch
(path, *args, **kwargs)¶ Use python mock to mock a path with automatic cleanup.
-
setUp
()¶ Run before each test method to initialize test environment.
-
start_service
(name, host=None, **kwargs)¶
-
stub_out
(old, new)¶ Replace a function for the duration of the test.
Use the monkey patch fixture to replace a function for the duration of a test. Useful when you want to provide fake methods instead of mocks during testing. This should be used instead of self.stubs.Set (which is based on mox) going forward.
-
-
exception
TestingException
¶ Bases:
Exception