allure-python-commons
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
- breaking Version 2.14.0 dropped official support for Python 3.7. Ensure your Python environment is 3.8 or newer for the latest versions of `allure-python-commons` and its adapters.
- gotcha Do not confuse `allure-python-commons` with older, incompatible Allure plugins like `pytest-allure-adaptor`. `allure-python-commons` provides the core API, while integrations like `allure-pytest` handle framework-specific logic. Using both or mixing old and new versions can lead to import errors and unexpected behavior.
- gotcha Custom labels added via `@allure.label` might not display directly in the default Allure Report HTML view. These labels are primarily intended for advanced filtering in Allure TestOps or for custom report processing.
- gotcha Using `allure-python-commons` alone will not generate an interactive HTML Allure Report. It provides the API for creating report data. To get a report, you must also install a specific Allure adapter for your test framework (e.g., `allure-pytest` for Pytest) and the separate Allure Report command-line tool (which requires Java to run).
- breaking Older versions of `allure-python-commons` (pre-2.x) had compatibility issues with newer Pytest versions (e.g., Pytest 3.2.0 and later), specifically concerning the location of internal classes like `XFail`, leading to import failures.
Install
-
pip install allure-python-commons
Imports
- allure
import allure
- LabelType
from allure_commons.types import LabelType
Quickstart
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.")