Slash leverages the gossip library to implement hooks. Hooks are endpoints to which you can register callbacks to be called in specific points in a test session lifetime.

All built-in hooks are members of the slash gossip group. As a convenience, the hook objects are all kept as globals in the slash.hooks module.

The slash gossip group is set to be both strict (See Gossip strict registrations) and has exception policy set to RaiseDefer (See Gossip error handling).

Registering Hooks

Hooks can be registered through slash.hooks:

import slash

def handler():
    print("Session has started: ", slash.context.session)

Which is roughly equivalent to:

import gossip

def handler():
      print("Session has started: ", slash.context.session)

Hook Errors

By default, exceptions propagate from hooks and on to the test, but first all hooks are attempted. In some cases though you may want to debug the exception close to its raising point. Setting debug.debug_hook_handlers to True will cause the debugger to be triggered as soon as the hook dispatcher encounteres the exception. This is done via gossip’s error handling mechanism.

Hooks and Plugins

Hooks are especially useful in conjunction with Plugins. By default, plugin method names correspond to hook names on which they are automatically registered upon activation.

See also


Advanced Usage

You may want to further customize hook behavior in your project. Mose of these customizations are available through gossip.

Available Hooks

The following hooks are available from the slash.hooks module:


Second entry point for session start, useful for plugins relying on other plugins’ session_start routine


Entry point which is called before session_start, useful for configuring plugins and other global resources


Called right before a test cleanups are executed


Called in parallel execution mode, before the parent starts the child worker


Configuration hook that happens during commandline parsing, and before plugins are activated. It is a convenient point to override plugin activation settings


Called right before entering debugger

slash.hooks.error_added(error, result)

Called when an error is added to a result (either test result or global)


Called whenever an exception is caught, and a debugger has already been run


Called whenever an exception is caught, but a debugger hasn’t been entered yet

slash.hooks.fact_set(name, value)

Called when a fact is set for a test


Called with a message object prior to it being sent via the notifications plugin (if enabled)


Called at the end of the execution, when printing results


Called right before the session ends, regardless of the reason for termination


Called when the session is interrupted unexpectedly


Called right after session starts


Called when a test is skipped completely (not even started)

slash.hooks.test_distributed(test_logical_id, worker_session_id)

Called in parallel mode, after the parent sent a test to child)


Called right before a test ends, regardless of the reason for termination


Called on test error


Called on test failure


Called when a test is interrupted by a KeyboardInterrupt or other similar means


Called on test skip


Called right after a test starts


Called on test success


Called when Slash finishes loading a batch of tests for execution (not necessarily al tests)


Called when a warning is captured by Slash


Called on new worker startup