How to use _load_plugins method in tavern

Best Python code snippet using tavern

discovery_mgr.py

Source:discovery_mgr.py Github

copy

Full Screen

...14import logging15from opsmgr.common.utils import entry_exit, load_plugin_by_namespace16I_DISCOVERY_PLUGIN = "opsmgr.discovery.interfaces.IDiscoveryPlugin"17@entry_exit(exclude_index=[], exclude_name=[])18def _load_plugins():19 """ Find the discovery provider plugins and return them as20 dictonary[name]=plugin class21 """22 return load_plugin_by_namespace(I_DISCOVERY_PLUGIN)23@entry_exit(exclude_index=[], exclude_name=[])24def list_plugins():25 return sorted(_load_plugins().keys())26@entry_exit(exclude_index=[], exclude_name=[])27def find_resources():28 plugins = _load_plugins()29 plugin_label = 'unknown' #keeps pylint happy30 message = None31 try:32 for plugin_label, plugin in plugins.items():33 plugin.find_resources()34 except Exception as e:35 logging.exception(e)36 message = _("Error in plugin (%s)::Unable to find resources - reason::%s") % \37 (plugin_label, e)38 return -1, message39 return 0, message40@entry_exit(exclude_index=[], exclude_name=[])41def import_resources(resource_label='*', offline=False):42 plugins = _load_plugins()43 plugin_label = 'unknown' #keeps pylint happy44 message = None45 try:46 for plugin_label, plugin in plugins.items():47 plugin.import_resources(resource_label, offline)48 except Exception as e:49 logging.exception(e)50 message = _("Error in plugin (%s)::Unable to import resource - reason::%s") % \51 (plugin_label, e)52 return -1, message...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

1import collections2import re3PluginInfo = collections.namedtuple('PluginInfo', ['name', 'cls', 'match', 'examples'])4def _load_plugins(class_name):5 import os6 import re7 import importlib8 items = []9 pat = re.compile(f'(.*_{class_name.lower()})\\.py$')10 my_folder = os.path.dirname(os.path.abspath(__file__))11 for item in os.listdir(my_folder):12 x = None13 m = pat.match(item)14 if m:15 plugin = m.group(1)16 module = importlib.import_module(f'.{plugin}', __name__)17 cls = getattr(module, class_name)18 if hasattr(module, 'match') and hasattr(module, 'EXAMPLES'):19 item = PluginInfo(plugin, cls, module.match, module.EXAMPLES)20 # Move file plugin to the end since it matches anything.21 if plugin.startswith('file'):22 items.append(item)23 else:24 items.insert(0, item)25 return items26SENDERS = _load_plugins('Sender')27RECEIVERS = _load_plugins('Receiver')28del _load_plugins29SENDER_EX = [x.examples for x in SENDERS]30RECEIVER_EX = [x.examples for x in RECEIVERS]31_UNLIKELY_FSPATH_PATH = re.compile('^[a-z][a-z0-9_.]{1,9}:')32def _seems_like_fspath(uri):33 return not bool(_UNLIKELY_FSPATH_PATH.match(uri))34def load(uri, items):35 for item in items:36 if item.match(uri):37 return item.cls(uri) if items is RECEIVERS else item.cls()38 msg = f"Can't find a transport that matches {uri}."39 if _seems_like_fspath(uri):40 msg += " Did you reference a file or folder that doesn't exist?"41 raise ValueError(msg)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tavern automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful