The nova.test Module

Base classes for our unit tests.

Allows overriding of flags for use of fakes, and some black magic for inline callbacks.

class APICoverage

Bases: object

cover_api = None
test_api_methods()
class BaseHookTestCase(*args, **kwargs)

Bases: nova.test.NoDBTestCase

assert_has_hook(expected_name, func)
class MatchType(wanttype)

Bases: object

Matches any instance of a specified type

The MatchType class is a helper for use with the mock.assert_called_with() method that lets you assert that a particular parameter has a specific data type. It enables strict check than the built in mock.ANY helper, and is the equivalent of the mox.IsA() function from the legacy mox library

Example usage could be:

mock_some_method.assert_called_once_with(
“hello”, MatchType(objects.Instance), mock.ANY, “world”, MatchType(objects.KeyPair))
class NoDBTestCase(*args, **kwargs)

Bases: nova.test.TestCase

NoDBTestCase differs from TestCase in that DB access is not supported. This makes tests run significantly faster. If possible, all new tests should derive from this class.

USES_DB = False
class SampleNetworks(host=None)

Bases: fixtures.fixture.Fixture

Create sample networks in the database.

setUp()
class TestCase(*args, **kwargs)

Bases: testtools.testcase.TestCase

Test case base class for all unit tests.

Due to the slowness of DB access, please consider deriving from NoDBTestCase first.

REQUIRES_LOCKING = False
TIMEOUT_SCALING_FACTOR = 1
USES_DB = True
assertJsonEqual(expected, observed)

Asserts that 2 complex data structures are json equivalent.

We use data structures which serialize down to json throughout the code, and often times we just need to know that these are json equivalent. This means that list order is not important, and should be sorted.

Because this is a recursive set of assertions, when failure happens we want to expose both the local failure and the global view of the 2 data structures being compared. So a MismatchError which includes the inner failure as the mismatch, and the passed in expected / observed as matchee / matcher.

assertPublicAPISignatures(baseinst, inst)
flags(**kw)

Override flag variables for a test.

setUp()

Run before each test method to initialize test environment.

start_service(name, host=None, **kwargs)
exception TestingException

Bases: exceptions.Exception

class TimeOverride

Bases: fixtures.fixture.Fixture

Fixture to start and remove time override.

setUp()
class skipIf(condition, reason)

Bases: object

Previous topic

The nova.servicegroup.drivers.zk Module

Next topic

The nova.utils Module

Project Source

This Page