allure-python-commons

2.15.3 · active · verified Thu Apr 09

allure-python-commons is a core Python library providing the API for end-users and helper functions/classes to build Allure adapters for various Python test frameworks. It is currently at version 2.15.3 and maintains a frequent release cadence with multiple minor/patch releases every few weeks or months, ensuring active development and support.

Warnings

Install

Imports

Quickstart

This example demonstrates basic usage of `allure.step` and `allure.attach` within a Python function. While `allure-python-commons` provides the API, generating an actual Allure Report requires integration with a test framework adapter (like `allure-pytest`) and the Allure Report command-line tool. The output will typically be `.json` and `.xml` files in a designated directory, which are then processed by the Allure CLI tool.

import allure
import os

def my_function_with_steps():
    with allure.step("Step 1: Perform initial setup"):
        print("Executing setup...")
        allure.attach("Setup log content", name="setup_log", attachment_type=allure.attachment_type.TEXT)

    with allure.step("Step 2: Process data"):
        data = "some_data_to_process"
        allure.dynamic.parameter("input_data", data)
        print(f"Processing data: {data}")
        processed_data = data.upper()
        allure.attach(processed_data, name="processed_output", attachment_type=allure.attachment_type.TEXT)

    with allure.step("Step 3: Final verification"):
        result = "success"
        allure.dynamic.label("result", result)
        print(f"Verification result: {result}")

if __name__ == "__main__":
    # In a real test framework (e.g., pytest), this function would be a test.
    # The Allure adapter would then capture these calls to build the report.
    print("Running a simulated test function using allure-python-commons API.")
    print("Note: To generate an actual Allure Report, you need a test runner (e.g., pytest) configured with an Allure adapter (e.g., allure-pytest) and the Allure Report CLI tool.")
    my_function_with_steps()
    print("API calls made. Check the output directory configured by your Allure adapter.")

view raw JSON →