CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-allure-python-commons

Contains the API for end users as well as helper functions and classes to build Allure adapters for Python test frameworks

Overall
score

94%

Overview
Eval results
Files

test-decorators.mddocs/

Test Decorators

Comprehensive set of decorators for enhancing test metadata and organization. These decorators allow tests to be annotated with titles, descriptions, labels, links, and organizational information that appears in Allure reports.

Capabilities

Test Identification and Documentation

Core decorators for providing human-readable test information and documentation.

def title(test_title):
    """
    Set a custom title for the test.
    
    Parameters:
    - test_title (str): The title to display in the report
    
    Returns:
    Function decorator
    """

def description(test_description):
    """
    Add a description to the test.
    
    Parameters:
    - test_description (str): Plain text description
    
    Returns:
    Function decorator
    """

def description_html(test_description_html):
    """
    Add an HTML description to the test.
    
    Parameters:
    - test_description_html (str): HTML formatted description
    
    Returns:
    Function decorator
    """

def id(id):
    """
    Set a unique identifier for the test.
    
    Parameters:
    - id (str): Unique test identifier
    
    Returns:
    Function decorator
    """

Usage Examples:

@allure.title("User Authentication Test")
@allure.description("Verifies that users can log in with valid credentials")
@allure.id("AUTH-001")
def test_user_login():
    pass

@allure.description_html("""
<h3>Complex Test Scenario</h3>
<ul>
    <li>Step 1: Initialize data</li>
    <li>Step 2: Execute operation</li>
    <li>Step 3: Verify results</li>
</ul>
""")
def test_complex_scenario():
    pass

Test Organization and Labeling

Decorators for organizing tests into hierarchical structures and adding categorical labels.

def label(label_type, *labels):
    """
    Add custom labels to the test.
    
    Parameters:
    - label_type (str): Type of label (from LabelType constants)
    - *labels: Variable number of label values
    
    Returns:
    Function decorator
    """

def severity(severity_level):
    """
    Set the test severity level.
    
    Parameters:
    - severity_level (Severity): Severity enum value
    
    Returns:
    Function decorator
    """

def tag(*tags):
    """
    Add tags to the test for filtering and organization.
    
    Parameters:
    - *tags: Variable number of tag strings
    
    Returns:
    Function decorator
    """

def epic(*epics):
    """
    Associate test with one or more epics.
    
    Parameters:
    - *epics: Variable number of epic names
    
    Returns:
    Function decorator
    """

def feature(*features):
    """
    Associate test with one or more features.
    
    Parameters:
    - *features: Variable number of feature names
    
    Returns:
    Function decorator
    """

def story(*stories):
    """
    Associate test with one or more user stories.
    
    Parameters:
    - *stories: Variable number of story names
    
    Returns:
    Function decorator
    """

Usage Examples:

@allure.severity(allure.severity_level.CRITICAL)
@allure.epic("User Management")
@allure.feature("Authentication")
@allure.story("User Login")
@allure.tag("smoke", "regression")
def test_critical_login():
    pass

@allure.label("owner", "qa-team")
@allure.label("layer", "api")
def test_api_endpoint():
    pass

Test Suite Organization

Decorators for organizing tests into suite hierarchies.

def suite(suite_name):
    """
    Set the test suite name.
    
    Parameters:
    - suite_name (str): Name of the test suite
    
    Returns:
    Function decorator
    """

def parent_suite(parent_suite_name):
    """
    Set the parent suite name for hierarchical organization.
    
    Parameters:
    - parent_suite_name (str): Name of the parent suite
    
    Returns:
    Function decorator
    """

def sub_suite(sub_suite_name):
    """
    Set the sub suite name for detailed organization.
    
    Parameters:
    - sub_suite_name (str): Name of the sub suite
    
    Returns:
    Function decorator
    """

Usage Examples:

@allure.parent_suite("E2E Tests")
@allure.suite("Authentication Suite")
@allure.sub_suite("Login Tests")
def test_user_login():
    pass

Links and References

Decorators for linking tests to external resources like bug trackers, test case management systems, and documentation.

def link(url, link_type=LinkType.LINK, name=None):
    """
    Add a link to the test.
    
    Parameters:
    - url (str): URL to link to
    - link_type (str): Type of link (from LinkType constants)
    - name (str, optional): Display name for the link
    
    Returns:
    Function decorator
    """

def issue(url, name=None):
    """
    Link to a bug or issue tracker.
    
    Parameters:
    - url (str): URL to the issue
    - name (str, optional): Display name for the issue
    
    Returns:
    Function decorator
    """

def testcase(url, name=None):
    """
    Link to a test case in a test management system.
    
    Parameters:
    - url (str): URL to the test case
    - name (str, optional): Display name for the test case
    
    Returns:
    Function decorator
    """

Usage Examples:

@allure.issue("https://jira.company.com/BUG-123", "Login Bug")
@allure.testcase("https://testcase.company.com/TC-456", "Login Test Case")
@allure.link("https://docs.company.com/auth", "Authentication Docs")
def test_login_with_references():
    pass

Manual Test Marking

Decorator for marking tests as manual execution tests.

def manual(fn):
    """
    Mark a test as requiring manual execution.
    
    Parameters:
    - fn: The test function to mark
    
    Returns:
    Decorated function
    """

Usage Example:

@allure.manual
def test_manual_verification():
    """This test requires manual verification of UI elements."""
    pass

Dynamic Test Enhancement

Class providing static methods for modifying test metadata at runtime during test execution.

class Dynamic:
    @staticmethod
    def title(test_title):
        """Set test title at runtime."""
    
    @staticmethod  
    def description(test_description):
        """Add description at runtime."""
    
    @staticmethod
    def description_html(test_description_html):
        """Add HTML description at runtime."""
    
    @staticmethod
    def label(label_type, *labels):
        """Add labels at runtime."""
    
    @staticmethod
    def severity(severity_level):
        """Set severity at runtime."""
    
    @staticmethod
    def epic(*epics):
        """Set epics at runtime."""
    
    @staticmethod
    def feature(*features):
        """Set features at runtime."""
    
    @staticmethod
    def story(*stories):
        """Set stories at runtime."""
    
    @staticmethod
    def tag(*tags):
        """Add tags at runtime."""
    
    @staticmethod
    def id(id):
        """Set test ID at runtime."""
    
    @staticmethod
    def link(url, link_type=LinkType.LINK, name=None):
        """Add link at runtime."""
    
    @staticmethod
    def parameter(name, value, excluded=None, mode=None):
        """Add parameter at runtime."""
    
    @staticmethod
    def issue(url, name=None):
        """Add issue link at runtime."""
    
    @staticmethod
    def testcase(url, name=None):
        """Add test case link at runtime."""
    
    @staticmethod
    def suite(suite_name):
        """Set suite at runtime."""
    
    @staticmethod
    def parent_suite(parent_suite_name):
        """Set parent suite at runtime."""
    
    @staticmethod
    def sub_suite(sub_suite_name):
        """Set sub suite at runtime."""
    
    @staticmethod
    def manual():
        """Mark as manual test at runtime."""

Usage Examples:

def test_dynamic_enhancement():
    # Modify test metadata based on runtime conditions
    if is_production_environment():
        allure.dynamic.severity(allure.severity_level.CRITICAL)
        allure.dynamic.tag("production")
    
    test_data = get_test_data()
    allure.dynamic.title(f"Test with data: {test_data['name']}")
    allure.dynamic.parameter("test_data", test_data)
    
    if test_data['type'] == 'regression':
        allure.dynamic.story("Regression Testing")

Constants and Enums

Severity Levels

class Severity(str, Enum):
    BLOCKER = 'blocker'
    CRITICAL = 'critical' 
    NORMAL = 'normal'
    MINOR = 'minor'
    TRIVIAL = 'trivial'

Link Types

class LinkType:
    LINK = 'link'
    ISSUE = 'issue'
    TEST_CASE = 'tms'

Label Types

class LabelType(str):
    EPIC = 'epic'
    FEATURE = 'feature'
    STORY = 'story'
    PARENT_SUITE = 'parentSuite'
    SUITE = 'suite'
    SUB_SUITE = 'subSuite'
    SEVERITY = 'severity'
    THREAD = 'thread'
    HOST = 'host'
    TAG = 'tag'
    ID = 'as_id'
    FRAMEWORK = 'framework'
    LANGUAGE = 'language'
    MANUAL = 'ALLURE_MANUAL'

Install with Tessl CLI

npx tessl i tessl/pypi-allure-python-commons

docs

data-models.md

index.md

plugin-system.md

test-decorators.md

test-lifecycle.md

utilities.md

tile.json