Contains the API for end users as well as helper functions and classes to build Allure adapters for Python test frameworks
Overall
score
94%
Complete set of data structures for representing Allure test results, containers, attachments, and metadata. These classes provide the object model for all Allure test data with proper serialization support for JSON output.
Main classes representing test execution results and their hierarchical organization.
class TestResult(ExecutableItem):
"""
Represents a single test case result.
Attributes:
- uuid (str): Unique identifier for the test
- historyId (str): Identifier for test history tracking
- testCaseId (str): Test case identifier from external system
- fullName (str): Full qualified test name
- labels (List[Label]): List of test labels
- links (List[Link]): List of external links
- titlePath (List[str]): Hierarchical title path
"""
# Pattern for JSON file naming
file_pattern = TEST_CASE_PATTERN
class TestResultContainer:
"""
Container for grouping related test results and fixtures.
Attributes:
- uuid (str): Unique identifier for the container
- name (str): Container display name
- children (List[str]): List of child test UUIDs
- description (str): Container description
- descriptionHtml (str): HTML formatted description
- befores (List[TestBeforeResult]): Before fixtures
- afters (List[TestAfterResult]): After fixtures
- links (List[Link]): List of external links
- start (int): Start timestamp in milliseconds
- stop (int): Stop timestamp in milliseconds
"""
# Pattern for JSON file naming
file_pattern = TEST_GROUP_PATTERNBase classes for items that can be executed and contain steps, attachments, and parameters.
class ExecutableItem:
"""
Base class for executable test items.
Attributes:
- name (str): Item display name
- status (str): Execution status (from Status constants)
- statusDetails (StatusDetails): Detailed status information
- stage (str): Execution stage
- description (str): Item description
- descriptionHtml (str): HTML formatted description
- steps (List[TestStepResult]): List of execution steps
- attachments (List[Attachment]): List of attached files/data
- parameters (List[Parameter]): List of test parameters
- start (int): Start timestamp in milliseconds
- stop (int): Stop timestamp in milliseconds
"""
class TestStepResult(ExecutableItem):
"""
Represents a single test step result.
Attributes:
- id (str): Step identifier
"""
class TestBeforeResult(ExecutableItem):
"""Represents a before fixture execution result."""
class TestAfterResult(ExecutableItem):
"""Represents an after fixture execution result."""Classes for representing test metadata, parameters, labels, and links.
class Parameter:
"""
Represents a test parameter.
Attributes:
- name (str): Parameter name
- value (str): Parameter value (stringified)
- excluded (bool): Whether parameter should be excluded from display
- mode (ParameterMode): Display mode for the parameter
"""
class Label:
"""
Represents a test label for categorization and filtering.
Attributes:
- name (str): Label name/type
- value (str): Label value
"""
class Link:
"""
Represents an external link associated with a test.
Attributes:
- type (str): Link type (from LinkType constants)
- url (str): Link URL
- name (str): Display name for the link
"""
class StatusDetails:
"""
Detailed information about test execution status.
Attributes:
- known (bool): Whether this is a known issue
- flaky (bool): Whether this test is flaky
- message (str): Status message
- trace (str): Exception stack trace
"""
class Attachment:
"""
Represents a file or data attachment.
Attributes:
- name (str): Display name for attachment
- source (str): File path or identifier
- type (str): MIME type of the attachment
"""Constants defining valid values for various status and type fields.
class Status:
"""Test execution status constants."""
FAILED = 'failed'
BROKEN = 'broken'
PASSED = 'passed'
SKIPPED = 'skipped'
UNKNOWN = 'unknown'
class ParameterMode(Enum):
"""Parameter display modes."""
HIDDEN = 'hidden' # Parameter hidden from display
MASKED = 'masked' # Parameter value masked (e.g., passwords)
DEFAULT = None # Default parameter display
class AttachmentType(Enum):
"""
Attachment MIME types with corresponding file extensions.
Each enum value contains (mime_type, extension) tuple.
"""
# Text formats
TEXT = ("text/plain", "txt")
CSV = ("text/csv", "csv")
TSV = ("text/tab-separated-values", "tsv")
URI_LIST = ("text/uri-list", "uri")
# Structured data formats
HTML = ("text/html", "html")
XML = ("application/xml", "xml")
JSON = ("application/json", "json")
YAML = ("application/yaml", "yaml")
PCAP = ("application/vnd.tcpdump.pcap", "pcap")
# Image formats
PNG = ("image/png", "png")
JPG = ("image/jpg", "jpg")
SVG = ("image/svg+xml", "svg")
GIF = ("image/gif", "gif")
BMP = ("image/bmp", "bmp")
TIFF = ("image/tiff", "tiff")
# Video formats
MP4 = ("video/mp4", "mp4")
OGG = ("video/ogg", "ogg")
WEBM = ("video/webm", "webm")
# Document formats
PDF = ("application/pdf", "pdf")Constants defining file naming patterns for different result types.
# File naming patterns
TEST_GROUP_PATTERN = "{prefix}-container.json" # Container files
TEST_CASE_PATTERN = "{prefix}-result.json" # Test result files
ATTACHMENT_PATTERN = '{prefix}-attachment.{ext}' # Attachment files
# JSON formatting
INDENT = 4 # Indentation level for JSON outputfrom allure_commons.model2 import (
TestResult, TestResultContainer, Label, Link, Parameter,
Status, AttachmentType
)
# Create a test result
test_result = TestResult()
test_result.uuid = "test-123"
test_result.name = "User Login Test"
test_result.fullName = "tests.auth.test_login.test_user_login"
test_result.status = Status.PASSED
test_result.start = 1609459200000 # timestamp
test_result.stop = 1609459205000 # timestamp
# Add labels
severity_label = Label()
severity_label.name = "severity"
severity_label.value = "critical"
test_result.labels.append(severity_label)
feature_label = Label()
feature_label.name = "feature"
feature_label.value = "Authentication"
test_result.labels.append(feature_label)
# Add links
bug_link = Link()
bug_link.type = "issue"
bug_link.url = "https://jira.company.com/BUG-123"
bug_link.name = "Related Bug"
test_result.links.append(bug_link)
# Add parameters
username_param = Parameter()
username_param.name = "username"
username_param.value = "testuser"
test_result.parameters.append(username_param)
password_param = Parameter()
password_param.name = "password"
password_param.value = "***"
password_param.mode = ParameterMode.MASKED
test_result.parameters.append(password_param)from allure_commons.model2 import (
TestResultContainer, TestBeforeResult, TestAfterResult
)
# Create a container for grouping tests
container = TestResultContainer()
container.uuid = "container-456"
container.name = "Authentication Test Suite"
container.start = 1609459180000
container.children = ["test-123", "test-124", "test-125"]
# Add before fixture
setup_fixture = TestBeforeResult()
setup_fixture.name = "setup_test_database"
setup_fixture.status = Status.PASSED
setup_fixture.start = 1609459185000
setup_fixture.stop = 1609459190000
container.befores.append(setup_fixture)
# Add after fixture
cleanup_fixture = TestAfterResult()
cleanup_fixture.name = "cleanup_test_data"
cleanup_fixture.status = Status.PASSED
cleanup_fixture.start = 1609459300000
cleanup_fixture.stop = 1609459305000
container.afters.append(cleanup_fixture)from allure_commons.model2 import Attachment, AttachmentType
# Create text attachment
log_attachment = Attachment()
log_attachment.name = "Test Execution Log"
log_attachment.source = "abc123-attachment.txt"
log_attachment.type = AttachmentType.TEXT.mime_type
# Create screenshot attachment
screenshot_attachment = Attachment()
screenshot_attachment.name = "Failure Screenshot"
screenshot_attachment.source = "def456-attachment.png"
screenshot_attachment.type = AttachmentType.PNG.mime_type
# Add to test result
test_result.attachments.extend([log_attachment, screenshot_attachment])from allure_commons.model2 import StatusDetails
# Create detailed status for failed test
status_details = StatusDetails()
status_details.known = False
status_details.flaky = True
status_details.message = "Connection timeout after 30 seconds"
status_details.trace = """
Traceback (most recent call last):
File "test_api.py", line 42, in test_connection
response = requests.get(url, timeout=30)
requests.exceptions.Timeout: Connection timeout
"""
# Add to test result
failed_test = TestResult()
failed_test.status = Status.FAILED
failed_test.statusDetails = status_detailsInstall with Tessl CLI
npx tessl i tessl/pypi-allure-python-commonsevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10