Skip to main content

Enables custom hooks for Vedro, allowing actions on events like startup, scenario execution, and cleanup

Project description

Vedro Hooks

PyPI Version License

vedro-hooks is a plugin for the Vedro testing framework that allows you to attach custom hooks to various testing events, such as startup, scenario execution, and cleanup. This enables you to perform specific actions automatically at different stages of the testing lifecycle.

Installation

To install vedro-hooks, you can use the vedro plugin install command:

$ vedro plugin install vedro-hooks

Ensure you have Vedro already installed in your environment. If not, you can install it using pip:

$ pip install vedro

Usage

To use vedro-hooks, you need to register your custom hooks in the vedro.cfg.py file. Below is an example setup:

from vedro.events import CleanupEvent, ScenarioRunEvent, StartupEvent
from vedro_hooks import on_cleanup, on_scenario_run, on_startup

@on_startup
def my_startup_hook(event: StartupEvent):
    print("Testing started!")

@on_scenario_run
def my_scenario_run_hook(event: ScenarioRunEvent):
    scenario = event.scenario_result.scenario
    print(f"Running scenario: {scenario.subject}")

@on_cleanup
def my_cleanup_hook(event: CleanupEvent):
    print("Testing finished!")

...

Sync and Async Hooks

vedro-hooks supports both synchronous and asynchronous hooks, allowing you to handle events in the way that best suits your needs:

Sync Hook Example

@on_scenario_passed
def my_sync_hook(event):
    scenario = event.scenario_result.scenario
    print(f"Scenario passed: {scenario.subject}")

Async Hook Example

@on_scenario_failed
async def my_async_hook(event):
    scenario = event.scenario_result.scenario
    print(f"Scenario failed: {scenario.subject}")

Available Decorators

  • @on_startup: Register a function to be executed when the testing process starts.
  • @on_scenario_run: Register a function to be executed when a scenario starts running.
  • @on_scenario_passed: Register a function to be executed when a scenario passes.
  • @on_scenario_failed: Register a function to be executed when a scenario fails.
  • @on_scenario_skipped: Register a function to be executed when a scenario is skipped.
  • @on_scenario_reported: Register a function to be executed when a scenario is reported.
  • @on_cleanup: Register a function to be executed when the testing process ends.

For more detailed information about the events these decorators can hook into, you can refer to the Vedro Plugin Guide.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vedro_hooks-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

vedro_hooks-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file vedro_hooks-0.1.0.tar.gz.

File metadata

  • Download URL: vedro_hooks-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure

File hashes

Hashes for vedro_hooks-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c94a31f6be935cdbf4d2dca8abd59530dc08196309d0749d6b7b5eaddbca11a1
MD5 22b8f0345e6676fad45bfe361ffe22dc
BLAKE2b-256 241a5d8a889723fee1ec29ec92402d4953632acf833208cb89e5fd6d172b680e

See more details on using hashes here.

File details

Details for the file vedro_hooks-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vedro_hooks-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure

File hashes

Hashes for vedro_hooks-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f1776114c8b699be5baf696526924acf694d16e388bfddd3c3f7590a13bc73bc
MD5 69c14567b64fcf211eca617a701d1dcd
BLAKE2b-256 2dec75005b7ae6ede22313c2f1abfe0565650b3da89459fd5b3a1b0d830999c3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page