Allure pytest integration that generates comprehensive test reports with rich metadata and visual test execution tracking
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Enhance test reporting with step-by-step execution tracking and rich attachments. Steps break down test execution into logical phases while attachments provide supporting evidence like screenshots, logs, and data files.
Create hierarchical test steps to document test execution flow and make debugging easier by identifying exactly where failures occur.
@allure.step(title: str)
"""
Decorator to mark a function as a test step.
Parameters:
- title: Step title (supports parameter formatting with {})
Usage:
@allure.step("Login with username {username}")
def login(username, password):
pass
"""
allure.step(title: str)
"""
Context manager for creating test steps.
Parameters:
- title: Step title for the step block
Usage:
with allure.step("Navigate to login page"):
driver.get("/login")
"""Attach external files like screenshots, logs, configuration files, and test data to test results.
allure.attach.file(source: str, name: str = None, attachment_type: str = None, extension: str = None)
"""
Attach an external file to the test result.
Parameters:
- source: Path to the file to attach
- name: Display name for the attachment (optional)
- attachment_type: MIME type of the file (optional, auto-detected if not provided)
- extension: File extension (optional, auto-detected if not provided)
Usage:
allure.attach.file("./logs/test.log", name="Test Log", attachment_type="text/plain")
allure.attach.file("./screenshots/error.png", name="Error Screenshot")
"""Attach in-memory data like API responses, database queries, or generated content directly to test results.
allure.attach(body: Any, name: str = None, attachment_type: str = None, extension: str = None)
"""
Attach data directly to the test result.
Parameters:
- body: Data to attach (string, bytes, or other serializable data)
- name: Display name for the attachment (optional)
- attachment_type: MIME type of the data (optional)
- extension: File extension for the attachment (optional)
Usage:
allure.attach(json.dumps(response), name="API Response", attachment_type="application/json")
allure.attach(screenshot_bytes, name="Screenshot", attachment_type="image/png")
"""import allure
def test_user_registration():
with allure.step("Navigate to registration page"):
driver.get("/register")
with allure.step("Fill registration form"):
driver.find_element("name", "username").send_keys("testuser")
driver.find_element("name", "email").send_keys("test@example.com")
driver.find_element("name", "password").send_keys("password123")
with allure.step("Submit registration"):
driver.find_element("type", "submit").click()
with allure.step("Verify successful registration"):
success_message = driver.find_element("class", "success").text
assert "Registration successful" in success_messageimport allure
@allure.step("Login with username '{username}'")
def login_user(username, password):
driver.find_element("name", "username").send_keys(username)
driver.find_element("name", "password").send_keys(password)
driver.find_element("type", "submit").click()
@allure.step("Navigate to page '{page_name}'")
def navigate_to_page(page_name, url):
driver.get(url)
def test_user_workflow():
login_user("testuser", "password123")
navigate_to_page("Dashboard", "/dashboard")import allure
import json
import requests
def test_api_integration():
with allure.step("Send API request"):
response = requests.get("https://api.example.com/users")
# Attach request details
allure.attach(
f"GET {response.url}\nStatus: {response.status_code}",
name="Request Details",
attachment_type="text/plain"
)
# Attach response data
allure.attach(
json.dumps(response.json(), indent=2),
name="API Response",
attachment_type="application/json"
)
with allure.step("Take screenshot of results"):
screenshot = driver.get_screenshot_as_png()
allure.attach(
screenshot,
name="API Results Screenshot",
attachment_type="image/png"
)
with allure.step("Save test log"):
allure.attach.file(
"./logs/api_test.log",
name="Test Execution Log",
attachment_type="text/plain"
)import allure
@allure.step("Setup test environment")
def setup_environment():
with allure.step("Start application server"):
# Start server logic
pass
with allure.step("Initialize database"):
# Database setup logic
pass
with allure.step("Configure test data"):
# Test data setup logic
pass
def test_complex_workflow():
setup_environment()
with allure.step("Execute main test logic"):
with allure.step("Perform user actions"):
# Test actions
pass
with allure.step("Validate results"):
# Assertions
passThe attachments appear in the Allure report and provide essential context for understanding test execution and debugging failures.
Install with Tessl CLI
npx tessl i tessl/pypi-allure-pytest