Move objects registration in tests directory

In order to use a NovaObject via the magic objects.Foo syntax
objects.register_all() must have been called first.  This was being done
in nova/test.py which most files in the test directory imported due to
TestCase being defined there.

Files in the test directory which provides fakes for use in testing do
not typically import nova.test and were not able to use objects.Foo to
instantiate an object.  This moves the objects registration to
tests/unit/__init__.py so that all modules in the unit tests directory
can access objects in the same way.  Since fakes are usually defined in
the unit tests dir this does not change anything for tests/functional/.

Change-Id: I7dee851cb4c37af3becf948cb55da5ee011a1e5e
This commit is contained in:
Andrew Laski 2015-08-12 15:12:30 -04:00
parent d403bf7649
commit d13cff65d0
2 changed files with 11 additions and 6 deletions

View File

@ -47,7 +47,6 @@ import testtools
from nova import context
from nova import db
from nova.network import manager as network_manager
from nova import objects
from nova.objects import base as objects_base
from nova.tests import fixtures as nova_fixtures
from nova.tests.unit import conf_fixture
@ -62,11 +61,6 @@ logging.register_options(CONF)
CONF.set_override('use_stderr', False)
logging.setup(CONF, 'nova')
# NOTE(comstud): Make sure we have all of the objects loaded. We do this
# at module import time, because we may be using mock decorators in our
# tests that run at import time.
objects.register_all()
_TRUE_VALUES = ('True', 'true', '1', 'yes')
if six.PY3:

View File

@ -24,4 +24,15 @@
import eventlet
from nova import objects
eventlet.monkey_patch(os=False)
# NOTE(alaski): Make sure this is done after eventlet monkey patching otherwise
# the threading.local() store used in oslo_messaging will be initialized to
# threadlocal storage rather than greenthread local. This will cause context
# sets and deletes in that storage to clobber each other.
# NOTE(comstud): Make sure we have all of the objects loaded. We do this
# at module import time, because we may be using mock decorators in our
# tests that run at import time.
objects.register_all()