or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

artifacts-files.mdassertions.mdcli.mdconfiguration.mdcontext-cleanup.mdevents.mdexecution-control.mdindex.mdparameterization.mdtest-definition.md
tile.json

tessl/pypi-vedro

Pragmatic Testing Framework for Python with BDD-style syntax and pluggable architecture

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/vedro@1.14.x

To install, run

npx @tessl/cli install tessl/pypi-vedro@1.14.0

index.mddocs/

Vedro

A pragmatic Python testing framework that combines clear, scenario-style syntax with a lightweight, pluggable core architecture. Vedro features BDD-style test structure, powerful parameterization, comprehensive event system, and extensive plugin ecosystem for customizing testing workflows.

Package Information

  • Package Name: vedro
  • Language: Python
  • Installation: pip install vedro
  • Console Entry Point: vedro command

Core Imports

import vedro

Common imports for test writing:

from vedro import Scenario, scenario, given, when, then, ensure
from vedro import params, skip, skip_if, only
from vedro import catched, context, defer, defer_global
from vedro import create_tmp_dir, create_tmp_file
from vedro import attach_artifact, attach_scenario_artifact

Configuration and core system imports:

from vedro import Config, computed
from vedro.core import Plugin, PluginConfig, Dispatcher
from vedro.events import StartupEvent, ScenarioPassedEvent, StepFailedEvent

Basic Usage

Class-based Scenarios

import vedro

class Scenario(vedro.Scenario):
    subject = "user authentication"
    
    def given_valid_credentials(self):
        self.username = "test_user" 
        self.password = "secure_pass"
        
    def when_user_logs_in(self):
        self.response = login(self.username, self.password)
        
    def then_login_is_successful(self):
        assert self.response.status_code == 200
        assert "token" in self.response.json()

Function-based Scenarios

from vedro import scenario, given, when, then, ensure

@scenario("User can view dashboard")
def test_dashboard_access():
    
    @given("authenticated user")
    def setup():
        return authenticate_user("test_user")
    
    @when("user requests dashboard")
    def action(user):
        return request_dashboard(user.token)
    
    @then("dashboard is displayed")
    def verification(response):
        ensure(response.status_code).equals(200)
        ensure("dashboard" in response.text)

Parameterized Scenarios

from vedro import Scenario, params

class Scenario(vedro.Scenario):
    subject = "math operations"
    
    @params(2, 3, 5)
    @params(5, 7, 12)
    @params(10, 15, 25)
    def __init__(self, a, b, expected):
        self.a = a
        self.b = b
        self.expected = expected
    
    def when_numbers_are_added(self):
        self.result = self.a + self.b
        
    def then_result_is_correct(self):
        assert self.result == self.expected

Architecture

Vedro follows an event-driven plugin architecture with clear separation of concerns:

  • Core Components: Scenario discovery, loading, execution, and result collection
  • Plugin System: Extensive plugin ecosystem with lifecycle hooks via event system
  • Event Dispatcher: Central event system enabling plugin communication and customization
  • Configuration: Hierarchical configuration system with factory/singleton patterns for dependency injection
  • CLI System: Command-based CLI with backward compatibility and extensible argument parsing

This architecture enables customization of every aspect of the testing process while maintaining simplicity for basic usage patterns.

Capabilities

Test Definition and Structure

Core functionality for defining and organizing test scenarios using class-based or function-based approaches with BDD-style step organization.

class Scenario:
    subject: str
    
def scenario(description: str) -> Callable
def given(description: str) -> Callable
def when(description: str) -> Callable  
def then(description: str) -> Callable

Test Definition

Test Parameterization

Powerful parameterization system supporting multiple parameter sets with optional decorators for enhanced functionality.

class params:
    def __init__(self, *args, **kwargs): ...
    def __call__(self, fn: F) -> F: ...
    def __class_getitem__(cls, item) -> Callable[..., Parameterized]: ...

Parameterization

Test Execution Control

Skip conditions, selective execution, and test flow control mechanisms for managing which tests run under different conditions.

def skip(reason: str = "") -> Callable
def skip_if(cond: Callable[[], bool], reason: str = "") -> Callable  
def only() -> Callable

Execution Control

Retry Logic and Exception Handling

Retry mechanism for flaky operations and sophisticated exception catching with inspection capabilities.

def ensure(*, attempts: Optional[int] = None,
           delay: Optional[Union[float, int, Callable[[int], Union[float, int]]]] = None,
           swallow: Optional[Union[Type[BaseException], Tuple[Type[BaseException], ...]]] = None) -> Ensure

class catched:
    def __init__(self, expected_exc = BaseException): ...
    @property
    def type(self) -> Type[BaseException] | None: ...
    @property  
    def value(self) -> BaseException | None: ...
    @property
    def traceback(self) -> TracebackType | None: ...

Retry Logic and Exception Handling

Artifacts and File Management

Comprehensive artifact attachment system and temporary file management with automatic cleanup.

class Artifact: ...
class FileArtifact(Artifact): ...
class MemoryArtifact(Artifact): ...

def attach_artifact(artifact: Artifact) -> None
def attach_scenario_artifact(artifact: Artifact) -> None
def attach_step_artifact(artifact: Artifact) -> None
def attach_global_artifact(artifact: Artifact) -> None

def create_tmp_dir(*, suffix: Optional[str] = None, prefix: Optional[str] = None) -> Path
def create_tmp_file(*, suffix: Optional[str] = None, prefix: Optional[str] = None) -> Path

Artifacts and Files

Context Management and Cleanup

Context providers and deferred cleanup actions for managing test state and resources.

def context(fn: Callable) -> Callable
def defer(fn: Callable, *args, **kwargs) -> None
def defer_global(fn: Callable, *args, **kwargs) -> None

Context and Cleanup

Event System

Comprehensive event system for plugin development and test lifecycle monitoring.

class Event: ...

# Lifecycle Events
class StartupEvent: ...
class CleanupEvent: ...

# Scenario Events  
class ScenarioRunEvent: ...
class ScenarioPassedEvent: ...
class ScenarioFailedEvent: ...
class ScenarioSkippedEvent: ...

# Step Events
class StepRunEvent: ...
class StepPassedEvent: ...
class StepFailedEvent: ...

Events

Configuration and Plugins

Configuration system with plugin management, dependency injection, and extensible architecture.

class Config:
    class Registry: ...
    class Plugins: ...
    
def computed(fn: Callable) -> Callable

class Plugin: ...
class PluginConfig: ...
class Dispatcher: ...

Configuration

CLI and Execution

Command-line interface for running tests and managing plugins with extensive configuration options.

def run(*, plugins=None) -> None

class Interface:
    """Base interface class for test scenarios."""
    pass

# CLI Commands
# vedro run [options]
# vedro version  
# vedro plugin [list|install|enable|disable]

CLI