Allure Python Integrations

repository·master·Indexed 21 days ago

https://github.com/allure-framework/allure-python

A collection of adapters that enable Python testing frameworks—including Pytest, Behave, Robot Framework, Pytest-BDD, and nose2—to generate interactive test reports using the Allure Report standard. It includes the allure-python-commons engine for building custom adapters, a Runtime API for dynamic report updates, and the allure-python-commons-test package for validating Allure2 JSON results using pyhamcrest matchers.

Tokens
35.2K
Snippets
137
Records
158
Agent score
73%

What's inside allure-python

  1. Overview of Allure Python Integrations

    master
    The allure-python repository provides a collection of adapters designed to integrate Allure Report with various Python-based testing frameworks. Instead of writing custom reporting logic, you can use these specialized packages to produce Allure-compatible test results from your existing test suites.
  2. Use Allure Python Commons for custom frameworks

    master
    The allure-python-commons package serves as the common engine for all the specific framework adapters. If you are building a custom or homemade testing framework and want to support Allure reporting, you should build your integration on top of this engine.
  3. Apply severity tags to Features and Scenarios in Behave

    master

    Severity tags can be applied at different levels of granularity in Gherkin:

    1. Scenario Level: Applying a tag directly to a Scenario sets the severity for that specific test case.
    2. Feature Level: Applying a tag to a Feature causes all scenarios within that feature to inherit that severity level.
    3. Precedence: If a scenario is affected by multiple severity tags (e.g., one from the Feature level and one from the Scenario level), the last one wins.
    @critical
    Feature: Allure severity support
        Scenario: This scenario inherits the @critical tag
            Given noop
    
        @minor @trivial
        Scenario: This is a trivial scenario
            Given noop
    
        Scenario: While this one is a blocker
            Given noop
  4. Create an Allure testplan JSON file

    master

    An Allure testplan is a JSON file that specifies which tests to run. It uses a tests array containing objects with either a selector (for name-based selection) or an id (for ID-based selection).

    • Selector: Use the format Testplan.<TestName> to select a test by its name.
    • ID: Use the allure.id:<value> tag in your Robot Framework tests and reference the <value> in the JSON id field.
    {
        "version":"1.0",
        "tests": [
            {
                "selector": "Testplan.Selected by Name"
            },
            {"id": "1008"}
        ]
    }
  5. Use docstrings as test descriptions

    master

    Allure automatically picks up the docstring of a test method and uses it as the test description in the report. This is a convenient way to add documentation without using additional decorators. This method supports Unicode characters.

    def test_docstring_description():
        """ Docstring """
        pass
    
    def test_unicode_docstring_description():
        """ Докстринг в юникоде """
        pass
  6. Run Behave with an Allure testplan

    master

    Set the ALLURE_TESTPLAN_PATH environment variable to the path of your JSON testplan file and run behave with the allure_behave.formatter:AllureFormatter.

    Linux or MacOS (bash):

    ALLURE_TESTPLAN_PATH=./testplan.json behave -f allure_behave.formatter:AllureFormatter -f pretty -o allure-results

    Windows (PowerShell):

    $Env:ALLURE_TESTPLAN_PATH = "./testplan.json"
    behave -f allure_behave.formatter:AllureFormatter -f pretty -o allure-results
  7. Add Allure links using Robot Framework tags

    master

    You can associate links with Robot Framework test cases by using specific tag patterns in the [Tags] section. The syntax follows the pattern allure.<LINK TYPE>[.<TEXT>]:<LINK>.

    Supported <LINK TYPE> values are:

    • link: For general web links.
    • issue: For bug tracking or issue management links.
    • tms: For Test Management System links.

    The <TEXT> part is optional. If omitted, the link URL itself will be used as the display text in the Allure report. If provided, it will be used as the link label.

    *** Test Cases ***
    Allure Plain Link
        [Tags]  allure.link:https://github.com/allure-framework/allure-python
        No Operation
    
    Allure Named Link
        [Tags]  allure.link.allure-python:https://github.com/allure-framework/allure-python
        No Operation
    
    Allure Issue Link
        [Tags]  allure.issue.ISSUE-1:https://github.com/allure-framework/allure-python/issues/1
        No Operation
    
    Allure TMS Link
        [Tags]  allure.tms.TESTCASE-1:https://my-tms/test-cases/1
        No Operation
  8. Install and use allure-pytest-bdd

    master

    To use Allure with Pytest-BDD, install the adapter via pip, run your tests using pytest with the --alluredir flag to specify the results directory, and then use the allure serve command to view the report.

    Note: Replace %allure_result_folder% with your desired directory path.

    $ pip install allure-pytest-bdd
    $ pytest --alluredir=%allure_result_folder% ./tests
    $ allure serve %allure_result_folder%
  9. Add a description to Behave scenarios via environment.py hooks

    master

    You can inject descriptions into scenarios using Behave hooks like before_scenario or after_scenario inside your environment.py file. This is useful for applying descriptions based on scenario names or other metadata.

    import allure
    
    def before_scenario(context, scenario):
        if "before_scenario" in scenario.name:
            allure.dynamic.description(
                "This scenario has a description specified in the "
                "before_scenario hook"
            )
    
    
    def after_scenario(context, scenario):
        if "after_scenario" in scenario.name:
            allure.dynamic.description(
                "This scenario has a description specified in the "
                "after_scenario hook"
            )
  10. Selectively run Behave tests using an Allure testplan

    master

    You can filter which test cases are executed by providing a JSON testplan file via the ALLURE_TESTPLAN_PATH environment variable. When running behave with the Allure formatter, only the tests explicitly listed in the testplan will be executed. Other tests will be marked as skipped in the console output.

    To use a testplan based on selectors, create a JSON file with a version and a tests array containing selector strings that match the feature/scenario names.

    {
        "version":"1.0",
        "tests": [
            {
                "selector": "Feature Name: Scenario Name"
            }
        ]
    }