From d13cff65d015c5715e922090d6e08fd147307937 Mon Sep 17 00:00:00 2001 From: Andrew Laski Date: Wed, 12 Aug 2015 15:12:30 -0400 Subject: [PATCH] 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 --- nova/test.py | 6 ------ nova/tests/unit/__init__.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/nova/test.py b/nova/test.py index 928e0d5aae34..88a9b3378903 100644 --- a/nova/test.py +++ b/nova/test.py @@ -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: diff --git a/nova/tests/unit/__init__.py b/nova/tests/unit/__init__.py index 6446a8a733ce..09d81a2d901b 100644 --- a/nova/tests/unit/__init__.py +++ b/nova/tests/unit/__init__.py @@ -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()