CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-vedro

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

49

1.08x
Quality

Pending

Does it follow best practices?

Impact

49%

1.08x

Average score across 10 eval scenarios

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

test-definition.mddocs/

Test Definition and Structure

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

Capabilities

Class-based Scenarios

The foundational Scenario class that uses metaclass magic to create test scenarios with automatic parameterization support.

class Scenario:
    """
    Base class for test scenarios with parameterization support.
    
    Attributes:
        subject (str): Description of what is being tested
    """
    subject: str
    
    def __repr__(self) -> str: ...

Usage Example

import vedro

class Scenario(vedro.Scenario):
    subject = "user registration process"
    
    def given_valid_user_data(self):
        self.user_data = {
            "username": "newuser",
            "email": "user@example.com", 
            "password": "securepass123"
        }
    
    def when_user_registers(self):
        self.response = register_user(self.user_data)
        
    def then_registration_succeeds(self):
        assert self.response.status_code == 201
        assert "user_id" in self.response.json()

Function-based Scenarios

Decorator-based approach for creating scenarios using functions with BDD-style step decorators.

def scenario(description: str) -> Callable:
    """
    Decorator to mark a function as a test scenario.
    
    Args:
        description: Human-readable description of the scenario
        
    Returns:
        Decorated function as a scenario
    """

BDD Step Decorators

Organize test logic into Given-When-Then structure for clarity and readability.

def given(description: str) -> Callable:
    """
    Decorator for setup/precondition steps.
    
    Args:
        description: Description of the precondition being set up
        
    Returns:
        Decorated function as a given step
    """

def when(description: str) -> Callable:
    """
    Decorator for action/event steps.
    
    Args:
        description: Description of the action being performed
        
    Returns:
        Decorated function as a when step
    """

def then(description: str) -> Callable:
    """
    Decorator for verification/assertion steps.
    
    Args:
        description: Description of the expected outcome
        
    Returns:
        Decorated function as a then step
    """

Usage Example

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

@scenario("User can reset password")
def test_password_reset():
    
    @given("user with forgotten password")
    def setup():
        user = create_user("test@example.com")
        return {"user": user, "original_password": user.password}
    
    @when("user requests password reset")
    def action(ctx):
        reset_token = request_password_reset(ctx["user"].email)
        new_password = "newpassword123"
        response = reset_password(reset_token, new_password)
        return {"response": response, "new_password": new_password}
    
    @then("password is successfully reset")
    def verification(ctx):
        ensure(ctx["response"].status_code).equals(200)
        
        # Verify old password no longer works
        with catched(AuthenticationError):
            authenticate(ctx["user"].email, ctx["original_password"])
            
        # Verify new password works
        auth_result = authenticate(ctx["user"].email, ctx["new_password"])
        ensure(auth_result.success).is_true()

Interface Class

Base interface class for plugin interfaces and extensibility.

class Interface:
    """
    Base interface class for plugin interfaces.
    """
    pass

Types

MetaData

Internal metadata handling for scenarios (used by the metaclass system).

class MetaData:
    """Internal metadata container for scenario information."""
    pass

Advanced Patterns

Method Organization

For class-based scenarios, organize methods with clear prefixes:

  • given_*: Setup and precondition methods
  • when_*: Action and event trigger methods
  • then_*: Verification and assertion methods

Nested Step Functions

Function-based scenarios support nested step definitions for complex test logic:

@scenario("Complex user workflow")
def test_complex_workflow():
    
    @given("authenticated user with permissions")
    def setup():
        user = authenticate_user("admin@example.com")
        grant_permissions(user, ["read", "write", "delete"])
        return user
    
    @when("user performs multiple actions")  
    def actions(user):
        # Multiple sub-actions
        created_item = create_item(user, {"name": "test item"})
        updated_item = update_item(user, created_item.id, {"status": "active"})
        return {"created": created_item, "updated": updated_item}
        
    @then("all actions succeed with proper state")
    def verification(ctx):
        ensure(ctx["created"].name).equals("test item")
        ensure(ctx["updated"].status).equals("active")
        
        # Verify database state
        db_item = get_item(ctx["created"].id)
        ensure(db_item.status).equals("active")

Subject Patterns

Use descriptive subjects that clearly indicate what functionality is being tested:

class Scenario(vedro.Scenario):
    subject = "payment processing with multiple payment methods"
    
class Scenario(vedro.Scenario):
    subject = "user authentication with two-factor authentication"
    
class Scenario(vedro.Scenario):
    subject = "file upload validation and processing"

docs

artifacts-files.md

assertions.md

cli.md

configuration.md

context-cleanup.md

events.md

execution-control.md

index.md

parameterization.md

test-definition.md

tile.json