Best Python code snippet using slash
test_interruptions.py
Source:test_interruptions.py
...8 interrupted_suite.run(expect_interruption=True)9def test_interruption_added_to_result(interrupted_suite, interrupted_index):10 caught = []11 @gossip.register('slash.interruption_added')12 def interruption_added(result, exception):13 caught.append(exception)14 summary = interrupted_suite.run(expect_interruption=True)15 assert len(caught) == 116 [err] = caught # pylint: disable=unbalanced-tuple-unpacking17 assert err.exception_type is KeyboardInterrupt18def test_interruption_triggers_gossip(request, interrupted_suite, interrupted_test):19 test_id = {'value': None}20 @gossip.register('slash.test_interrupt')21 def skip():22 test_id['value'] = slash.test.__slash__.id23 @request.addfinalizer24 def cleanup():25 skip.gossip.unregister()26 summary = interrupted_suite.run(expect_interruption=True)...
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!!