Pragmatic Testing Framework for Python with BDD-style syntax and pluggable architecture
49
Pending
Does it follow best practices?
Impact
49%
1.08xAverage score across 10 eval scenarios
Pending
The risk profile of this skill
Core functionality for defining and organizing test scenarios using class-based or function-based approaches with BDD-style step organization.
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: ...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()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
"""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
"""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()Base interface class for plugin interfaces and extensibility.
class Interface:
"""
Base interface class for plugin interfaces.
"""
passInternal metadata handling for scenarios (used by the metaclass system).
class MetaData:
"""Internal metadata container for scenario information."""
passFor class-based scenarios, organize methods with clear prefixes:
given_*: Setup and precondition methodswhen_*: Action and event trigger methodsthen_*: Verification and assertion methodsFunction-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")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
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10