Writing Plugins
Please note that this documentation page is currently undergoing finalization and improvements
Vedro is designed with an event-driven architecture, making it highly extensible and customizable. The event-based nature of Vedro plugins allows developers to tap into various points in the testing process and execute custom actions based on specific events.
In an event-driven system, components communicate with each other through events, which are essentially notifications that represent a change in the system's state or occurrence of an action. When an event occurs, any subscribed listener receives a notification and can react accordingly.
Plugin Structure
A typical Vedro plugin consists of a class that inherits from Plugin
and implements the subscribe
method. This method takes a Dispatcher
as an argument and registers the plugin's event listeners.
Here's an example of a basic plugin structure:
# ./custom_plugin.py
from vedro.core import Dispatcher, Plugin, PluginConfig
class CustomPlugin(Plugin):
def subscribe(self, dispatcher: Dispatcher) -> None:
pass
class Custom(PluginConfig):
plugin = CustomPlugin
Registering the Plugin
To enable the custom plugin in your Vedro application, you need to add it to the vedro.cfg.py
configuration file:
# ./vedro.cfg.py
import vedro
import custom_plugin
class Config(vedro.Config):
class Plugins(vedro.Config.Plugins):
class Custom(custom_plugin.Custom):
enabled = True
Plugin Lifecycle
Vedro plugins can listen to various events that occur during the test execution lifecycle. The following diagram shows the sequence of events:
ConfigLoadedEvent
|
ArgParseEvent
|
ArgParsedEvent
|
StartupEvent
/ \
ScenarioSkippedEvent ScenarioRunEvent
| |
| StepRunEvent
| / \
| StepPassedEvent StepFailedEvent
| | |
| ScenarioPassedEvent ScenarioFailedEvent
\ \ /
\ /
\ /
ScenarioReportedEvent
|
CleanupEvent
Listening to Events
To make your plugin listen to specific events, you need to implement the appropriate event listeners within the subscribe
method. The following sections provide examples for each event.