Best Python code snippet using slash
test_requirements.py
Source:test_requirements.py  
...137def test_unmet_requirements_trigger_avoided_test_hook(suite, suite_test):138    suite_test.add_decorator(_UNMET_REQ_DECORATOR)139    suite_test.expect_skip()140    @gossip.register("slash.test_avoided")141    def test_avoided(reason):  # pylint: disable=unused-variable142        slash.context.result.data["avoided"] = {143            "reason": reason,144            "test_name": slash.context.test.__slash__.address,145        }146    summary = suite.run()147    avoided_result = summary[suite_test]148    for r in summary.session.results.iter_all_results():149        if r is avoided_result:150            assert "avoided" in r.data151            assert "lambda" in r.data["avoided"]["reason"]152            assert "unmet requirement" in r.data["avoided"]["reason"].lower()153            assert r.data["avoided"]["test_name"].split("_")[-1] == suite_test.id154        else:155            assert "avoided" not in r.data...runner.py
Source:runner.py  
...115        else:116            msg = 'Unmet requirement: {}'.format(message or req)117            context.result.add_skip(msg)118        messages.add(msg)119    hooks.test_avoided(reason=', '.join(messages)) # pylint: disable=no-member120    return False121def _process_exclusions(test):122    if is_excluded(test):123        reason = 'Excluded due to parameter combination exclusion rules'124        context.result.add_skip(reason)125        hooks.test_avoided(reason=reason) # pylint: disable=no-member126        return False127    return True128class TestStartEndController(object):129    def __init__(self, result, prev_result):130        self._result = result131        self._prev_result = prev_result132        self._started = False133    def __enter__(self):134        return self135    def start(self):136        if not self._started:137            self._started = True138            self._result.mark_started()139            hooks.test_start() # pylint: disable=no-member...hooks.py
Source:hooks.py  
1import gossip2from vintage import deprecated3from .conf import config4def register(func):5    """A shortcut for registering hook functions by their names6    """7    return gossip.register('slash.{}'.format(func.__name__))(func)8def _deprecated_to_gossip(func):9    return deprecated(since="0.6.0", message="Use gossip instead")(func)10def _define(hook_name, **kwargs):11    hook = gossip.define("slash.{}".format(hook_name), **kwargs)12    globals()[hook_name] = hook13    return hook14_define('session_start', doc="Called right after session starts")15_define('session_end', doc="Called right before the session ends, regardless of the reason for termination")16_define('session_interrupt', doc='Called when the session is interrupted unexpectedly')17_define('tests_loaded', doc='Called when Slash finishes loading a batch of tests for execution (not necessarily al tests)', arg_names=('tests',))18_define('before_session_start', doc="Entry point which is called before session_start, useful for configuring plugins and other global resources")19_define('after_session_start', doc="Second entry point for session start, useful for plugins relying on other plugins' session_start routine")20_define('before_session_cleanup', doc="Called right before session cleanup begins")21_define('after_session_end', doc="Called right after session_end hook")22_define('app_quit', doc="Called right before the app quits")23_define('configure', doc='Configuration hook that happens during commandline parsing, and before plugins are activated. It is a convenient point to override plugin activation settings')  # pylint: disable=line-too-long24_define('test_interrupt', doc="Called when a test is interrupted by a KeyboardInterrupt or other similar means")25_define('test_avoided', doc="Called when a test is skipped completely (not even started)", arg_names=('reason',))26_define('test_start', doc="Called right after a test starts")27_define('test_distributed', doc="Called in parallel mode, after the parent sent a test to child)", arg_names=('test_logical_id', 'worker_session_id',)) # pylint: disable=line-too-long28_define('test_end', doc="Called right before a test ends, regardless of the reason for termination")29_define('log_file_closed', doc="Called right after a log file was closed", arg_names=('path', 'result',))30_define('before_test_cleanups', doc="Called right before a test cleanups are executed")31_define('test_success', doc="Called on test success")32_define('test_error', doc="Called on test error")33_define('test_failure', doc="Called on test failure")34_define('test_skip', doc="Called on test skip", arg_names=("reason",))35_define('worker_connected', doc="Called on new worker startup", arg_names=("session_id",))36_define('error_added', doc='Called when an error is added to a result (either test result or global)', arg_names=('error', 'result'))37_define('interruption_added', doc='Called when an exception is encountered that triggers test or session interruption',38        arg_names=('result', 'exception'))39_define('fact_set', doc='Called when a fact is set for a test', arg_names=['name', 'value'])40_define('warning_added', doc='Called when a warning is captured by Slash', arg_names=('warning',))41_define('result_summary', doc="Called at the end of the execution, when printing results")42_define('exception_caught_before_debugger',43        doc="Called whenever an exception is caught, but a debugger hasn't been entered yet")44_define('entering_debugger', doc='Called right before entering debugger', arg_names=('exc_info',))45_define('exception_caught_after_debugger',46        doc="Called whenever an exception is caught, and a debugger has already been run")47_define('before_worker_start', doc="Called in parallel execution mode, before the parent starts the child worker",48        arg_names=("worker_config",))49_define('prepare_notification', doc='Called with a message object prior to it being sent via the notifications plugin (if enabled)',50        arg_names=("message",))51_define('before_interactive_shell', doc='Called before starting interactive shell', arg_names=("namespace",))52_slash_group = gossip.get_group('slash')53_slash_group.set_strict()54_slash_group.set_exception_policy(gossip.RaiseDefer())55@gossip.register('gossip.on_handler_exception') # pylint: disable=unused-argument56def debugger(handler, exception, hook): # pylint: disable=unused-argument57    from .exception_handling import handle_exception58    if hook.group is _slash_group and config.root.debug.debug_hook_handlers:59        handle_exception(exception)60@_deprecated_to_gossip61def add_custom_hook(hook_name):62    """63    Adds an additional hook to the set of available hooks64    """65    return _define(hook_name)66@_deprecated_to_gossip67def ensure_custom_hook(hook_name):68    """69    Like :func:`.add_custom_hook`, only forgives if the hook already exists70    """71    try:72        return gossip.get_hook("slash.{}".format(hook_name))73    except LookupError:74        return _define(hook_name)75@_deprecated_to_gossip76def remove_custom_hook(hook_name):77    """78    Removes a hook from the set of available hooks79    """80    gossip.get_hook("slash.{}".format(hook_name)).undefine()81    globals().pop(hook_name)82@_deprecated_to_gossip83def get_custom_hook_names():84    """85    Retrieves the names of all custom hooks currently installed86    """87    raise NotImplementedError()  # pragma: no cover88@_deprecated_to_gossip89def get_all_hooks():90    return [91        (hook.name, hook)92        for hook in gossip.get_group('slash').get_hooks()]93@_deprecated_to_gossip94def get_hook_by_name(hook_name):95    """96    Returns a hook (if exists) by its name, otherwise returns None97    """...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
