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
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:

“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.

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.

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)

Override flag variables for a test.


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: exceptions.Exception

class TimeOverride

Bases: fixtures.fixture.Fixture

Fixture to start and remove time override.

class skipIf(condition, reason)

Bases: object

Previous topic

The nova.signature_utils Module

Next topic

The nova.utils Module

Project Source

This Page