Pragmatic Testing Framework for Python with BDD-style syntax and pluggable architecture
npx @tessl/cli install tessl/pypi-vedro@1.14.0A 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.
pip install vedrovedro commandimport vedroCommon 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_artifactConfiguration and core system imports:
from vedro import Config, computed
from vedro.core import Plugin, PluginConfig, Dispatcher
from vedro.events import StartupEvent, ScenarioPassedEvent, StepFailedEventimport 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()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)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.expectedVedro follows an event-driven plugin architecture with clear separation of concerns:
This architecture enables customization of every aspect of the testing process while maintaining simplicity for basic usage patterns.
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) -> CallablePowerful 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]: ...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() -> CallableRetry 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
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) -> PathContext 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) -> NoneComprehensive 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: ...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: ...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]