Skip tests when loading plugins
All python files in plugins were automatically loaded which would add the dependencies of the tests to the plugins. Let skip the files in the .tests. namespace Closes-Bug: #1292655 Change-Id: I25eac87559b5852e9645fbb84c8b4d07b4c1ff42
This commit is contained in:
parent
44f91f0186
commit
8c73c49dfe
@ -507,6 +507,14 @@ the engine will make them available next time the service starts.
|
||||
See one of the Installation Guides at http://docs.OpenStack.org/ for
|
||||
more information on configuring the orchestration service.
|
||||
|
||||
Testing
|
||||
-------
|
||||
|
||||
Tests can live inside the plug-in under the ``tests``
|
||||
namespace/directory. The Heat plug-in loader will implicitly not load
|
||||
anything under that directory. This is useful when your plug-in tests
|
||||
have dependencies you don't want installed in production.
|
||||
|
||||
Putting It All Together
|
||||
-----------------------
|
||||
You can find the plugin classes in ``heat/engine/resources``. An
|
||||
|
@ -86,6 +86,11 @@ def load_modules(package, ignore_error=False):
|
||||
|
||||
for importer, module_name, is_package in pkgutil.walk_packages(path,
|
||||
pkg_prefix):
|
||||
# NOTE(chmouel): Skips tests package or this will try to load
|
||||
# them when loading plugins.
|
||||
if '.tests.' in module_name:
|
||||
continue
|
||||
|
||||
try:
|
||||
module = _import_module(importer, module_name, package)
|
||||
except ImportError:
|
||||
|
@ -15,6 +15,7 @@
|
||||
import pkgutil
|
||||
import sys
|
||||
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from heat.common import plugin_loader
|
||||
@ -64,3 +65,14 @@ class PluginLoaderTest(testtools.TestCase):
|
||||
self.assertIsNone(plugin_loader._import_module(importer,
|
||||
'wibble',
|
||||
heat.engine))
|
||||
|
||||
@mock.patch.object(plugin_loader, "_import_module", mock.MagicMock())
|
||||
@mock.patch('pkgutil.walk_packages')
|
||||
def test_load_modules_skip_test(self, mp):
|
||||
importer = pkgutil.ImpImporter(heat.engine.__path__[0])
|
||||
|
||||
mp.return_value = ((importer, "hola.foo", None),
|
||||
(importer, "hola.tests.test_foo", None))
|
||||
loaded = plugin_loader.load_modules(
|
||||
heat.engine, ignore_error=True)
|
||||
self.assertEqual(1, len(list(loaded)))
|
||||
|
@ -90,10 +90,27 @@ class TestPluginManager(HeatTestCase):
|
||||
self.assertTrue(module.__name__.startswith('heat.tests') or
|
||||
module.__name__.startswith('heat.engine.plugins'))
|
||||
|
||||
def test_load_all(self):
|
||||
def test_load_all_skip_tests(self):
|
||||
mgr = plugin_manager.PluginManager('heat.tests')
|
||||
pm = plugin_manager.PluginMapping('current_test')
|
||||
|
||||
all_items = pm.load_all(mgr)
|
||||
|
||||
for item in current_test_mapping().iteritems():
|
||||
self.assertNotIn(item, all_items)
|
||||
|
||||
def test_load_all(self):
|
||||
import heat.tests.test_plugin_manager
|
||||
mgr = plugin_manager.PluginManager('heat.tests')
|
||||
pm = plugin_manager.PluginMapping('current_test')
|
||||
|
||||
# NOTE(chmou): We force the modules to be ourself so we can get
|
||||
# the current_test_mapping if not we will would be
|
||||
# skipped by plugin_loader.load_modules since we are skipping
|
||||
# the loading of the package with tests in there
|
||||
mgr.modules = [heat.tests.test_plugin_manager]
|
||||
|
||||
all_items = pm.load_all(mgr)
|
||||
|
||||
for item in current_test_mapping().iteritems():
|
||||
self.assertIn(item, all_items)
|
||||
|
Loading…
Reference in New Issue
Block a user