### Quick Start Installation and Reporting Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest-bdd/README.md These commands provide a quick start guide to install the allure-pytest-bdd package, run tests with Allure reporting enabled, and serve the generated report. Replace `%allure_result_folder%` with your desired directory for Allure results. ```Shell $ pip install allure-pytest-bdd $ pytest --alluredir=%allure_result_folder% ./tests $ allure serve %allure_result_folder% ``` -------------------------------- ### Quick Start: Install and Generate Allure Report with Pytest Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/README.md These commands demonstrate how to install the allure-pytest plugin using pip, run pytest tests to generate Allure results in a specified directory, and then serve the generated Allure report locally. ```shell $ pip install allure-pytest $ pytest --alluredir=%allure_result_folder% ./tests $ allure serve %allure_result_folder% ``` -------------------------------- ### Quick Start with Allure Behave Formatter Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/README.md Provides the necessary shell commands to install the allure-behave package, run Behave tests using the AllureFormatter, and serve the generated Allure report. ```shell $ pip install allure-behave $ behave -f allure_behave.formatter:AllureFormatter -o %allure_result_folder% ./features $ allure serve %allure_result_folder% ``` -------------------------------- ### Install and Use Allure Robot Framework Listener Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/README.md Installs the allure-robotframework library using pip and then runs a Robot Framework test suite with the Allure listener enabled. ```Shell $ pip install allure-robotframework $ robot --listener allure_robotframework ./my_robot_test ``` -------------------------------- ### Robot Framework Test Data Example Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/testplan.rst Example Robot Framework test cases used to demonstrate test selection via an Allure testplan. Includes tests identifiable by name and Allure ID. ```robotframework *** Test Cases *** Selected by Name No Operation Selected by ID [Tags] allure.id:1008 No Operation Not Selected [Tags] allure.id:1009 No Operation ``` -------------------------------- ### Running Robot Framework with Testplan (Shell) Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/testplan.rst A shell command example for Linux/bash showing how to execute Robot Framework tests using the Allure testplan. It sets the environment variable and applies the testplan modifier. ```shell ALLURE_TESTPLAN_PATH=./testplan.json robot --log NONE --report NONE --output NONE --extension robot --loglevel DEBUG --listener allure_robotframework:./allure-results --prerunmodifier allure_robotframework.testplan ./testplan.robot ``` -------------------------------- ### Robot Framework Tags Not Converted to Allure Tags Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/tag.rst Shows examples of Robot Framework tags that start with 'allure.' but are not automatically converted into standard Allure tags, such as 'allure.label.as_id' or 'allure.feature'. ```robotframework *** Test Cases *** No Allure Tags [Tags] allure.label.as_id:1008 allure.feature:Allure tags support No Operation ``` -------------------------------- ### Specifying Python Dependencies Source: https://github.com/allure-framework/allure-python/blob/master/requirements/linting.txt These lines define the necessary packages for the project. The '-r' option includes dependencies from another requirements file, while the subsequent lines list specific packages to install. ```Python -r ./core.txt flake8 flake8-builtins ``` -------------------------------- ### Apply Static Allure Tags in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/tag.rst Demonstrates how standard Robot Framework tags (not starting with 'allure.') are automatically converted into Allure tags when defined statically in the test case's [Tags] setting. ```robotframework *** Test Cases *** Distributed Legacy Test [Tags] distributed legacy No Operation ``` -------------------------------- ### Include External Requirements Files (requirements.txt) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/requirements.txt Specifies dependencies by referencing other requirements files. The `-r` flag tells pip to recursively install packages listed in the specified file. ```requirements.txt -r ../requirements/testing.txt -r ../requirements/linting.txt -r ../requirements/testing/allure-behave.txt ``` -------------------------------- ### Gherkin Feature for Dynamic Allure Links Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/link.rst Defines a Gherkin scenario used in the example demonstrating how to add Allure links dynamically from Python code (step definitions and hooks). ```gherkin Feature: Allure link support Scenario: Issue from the step definition and link from the hook Given a link is associated with this test case ``` -------------------------------- ### Add Allure Labels from Python Test Library Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/label.rst Provides an example of a Python function within a test library that adds Allure labels using decorators (`@allure.label`, `@allure.severity`) and dynamic functions (`allure.dynamic.label`, `allure.dynamic.suite`). This requires the `allure-python` library. ```python import allure import os @allure.label("layer", "API") @allure.severity(allure.severity_level.CRITICAL) def open_api(host, port): allure.dynamic.label("endpoint", f"{host}:{port}") allure.dynamic.suite(f"Testing API at {host}") ``` -------------------------------- ### Attaching Files with Name and Type in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/attachment.rst Similar to data attachments, you can specify a custom name and type for file attachments using the `Attach File` keyword. This example attaches a text file with a specific name and type. ```robotframework *** Settings *** Library AllureLibrary *** Test Cases *** File Attachment Attach File ./my_file.txt ... name=my-file attachment_type=TEXT ``` -------------------------------- ### Example Test Function (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/suite/module_level_custom_suite.rst A simple pytest test function demonstrating how tests within this module will inherit the module-level Allure suite name set by `pytestmark`. ```python def test_module_level_custom_suite(): pass ``` -------------------------------- ### Attaching Text Data with Name and Type in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/attachment.rst The `Attach` keyword allows specifying a custom name and attachment type for the data. This example attaches a list of URIs with a specific name and type. ```robotframework *** Settings *** Library AllureLibrary *** Variables *** ${links} https://github.com/allure-framework/allure2 ... https://github.com/allure-framework/allure-python *** Test Cases *** Data Attachment Attach ${links} ... name=links attachment_type=URI_LIST ``` -------------------------------- ### Add Allure TMS Link via Robot Framework Tag Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/link.rst Provides an example of adding a test management system (TMS) link to a Robot Framework test case using the allure.tms.: tag format. This connects the test result to its corresponding entry in a TMS. ```robotframework *** Test Cases *** Allure TMS Link [Tags] allure.tms.TESTCASE-1:https://my-tms/test-cases/1 No Operation ``` -------------------------------- ### Include Requirements File - Text Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest-bdd/requirements.txt The '-r' option in a requirements file specifies another requirements file to be recursively installed. This is useful for grouping related dependencies or separating development/testing dependencies from core dependencies. ```Text -r ../requirements/testing.txt -r ../requirements/linting.txt -r ../requirements/testing/allure-pytest-bdd.txt ``` -------------------------------- ### Attaching Textual Data in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/attachment.rst Use the `Attach` keyword to add textual data to your test results in Allure reports. This snippet shows a basic example of attaching a variable containing a message. ```robotframework *** Settings *** Library AllureLibrary *** Variables *** ${log_message} This attachment was created using the allure_robotframework ... library *** Test Cases *** Data Attachment Attach ${log_message} ``` -------------------------------- ### Applying Different Allure BDD Labels (Epic, Feature, Story) in Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/bdd/select_tests_by_bdd.rst Provides another example of applying Allure BDD labels for epic, feature, and story with different values. This demonstrates how different label values affect filtering. ```Python @allure.epic("Another Epic") @allure.feature("Another Feature") @allure.story("Another Story") def test_with_another_epic_feature_story(): pass ``` -------------------------------- ### Allure Python Editable Requirements Source: https://github.com/allure-framework/allure-python/blob/master/requirements/commons.txt These lines specify packages to be installed in editable mode (`-e`), which is common for local development or testing where changes to the package source code need to be reflected without reinstallation. They list the core common components and the test utilities for Allure Python. ```Requirements -e allure-python-commons -e allure-python-commons-test ``` -------------------------------- ### Adding Custom Label to Behave Scenario (Gherkin) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/label.rst Demonstrates how to apply a custom Allure label to a Behave scenario using the `@allure.label.:` tag directly in the Gherkin feature file. This example adds an 'author' label with the value 'John-Doe'. Note that label names and values cannot contain whitespace. ```Gherkin Feature: Allure label for behave tests @allure.label.author:John-Doe Scenario: Scenario marked with an author label Given noop ``` -------------------------------- ### Setting Multiline Documentation with [Documentation] in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/description.rst Shows how to define multiline documentation for a Robot Framework test case using the [Documentation] setting and the '...' continuation marker. The combined text forms the Allure test case description. ```Robot Framework *** Test Cases ***\nMultiline doc from the setting\n [Documentation] This documentation contains multiple lines of text.\n ... It will also appear as allure description.\n No Operation ``` -------------------------------- ### Using Python Library with Allure Steps in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/step.rst This Robot Framework test data file demonstrates how to import and use the Python library containing Allure step definitions. The test case calls a function from the library, which in turn executes the defined Allure steps and substeps, resulting in a structured Allure report. ```robotframework *** Settings *** Library ./my_lib.py *** Test Cases *** Allure substeps Substep ``` -------------------------------- ### Use Python Library to Apply Allure Labels in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/label.rst Shows how to import a Python test library that defines Allure labels and call its keywords from a Robot Framework test case to apply those labels to the test result. ```robotframework *** Settings *** Library ./my_library.py *** Test Cases *** Test backend API [Documentation] Four labels should be attached to this test result. Open API host=localhost ... port=443 ``` -------------------------------- ### Running Behave with Allure Testplan (Bash Export) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/testplan.rst Alternative command to run Behave tests with the Allure formatter, exporting the ALLURE_TESTPLAN_PATH environment variable before execution. ```bash export ALLURE_TESTPLAN_PATH=./testplan.json behave -f allure_behave.formatter:AllureFormatter -f pretty -o allure-results ``` -------------------------------- ### Defining Allure Steps in Python Library Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/step.rst This Python code demonstrates how to define functions that will appear as Allure steps. It shows the use of the `@allure.step` decorator for a function parameterizing the step name and the `with allure.step(...)` context manager for defining a step block within a function. ```python import allure @allure.step("Substep {parameter}") def substep_with_decorator(parameter): pass def substep(): with allure.step("Library substep"): substep_with_decorator("A") pass ``` -------------------------------- ### Importing Allure and Pytest Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/link/dynamic_link.rst Imports the necessary libraries, `allure` for reporting features and `pytest` for test framework capabilities. ```python import allure import pytest ``` -------------------------------- ### Running Behave with Allure Testplan (Bash) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/testplan.rst Command to run Behave tests with the Allure formatter, specifying the testplan file path via the ALLURE_TESTPLAN_PATH environment variable. ```bash ALLURE_TESTPLAN_PATH=./testplan.json behave -f allure_behave.formatter:AllureFormatter -f pretty -o allure-results ``` -------------------------------- ### Setting Documentation Dynamically with Set Test Documentation Keyword in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/description.rst Illustrates how to set or update the test case documentation dynamically during execution using the built-in Robot Framework keyword 'Set Test Documentation'. This dynamically set documentation will be used as the Allure description. ```Robot Framework *** Test Cases ***\nMultiline doc from the keyword\n Set Test Documentation This documentation will appear as allure description. ``` -------------------------------- ### Defining a Simple Behave Step (noop) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/description.rst This Python snippet provides a basic step definition for the 'Given noop' step used in the accompanying Gherkin feature file. It uses the Behave framework's `@given` decorator and simply passes, serving as a placeholder step. ```python from behave import given @given("noop") def step_impl(context): pass ``` -------------------------------- ### Attaching Files in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/attachment.rst Use the `Attach File` keyword to attach a file from the filesystem to your test result. This snippet demonstrates attaching a simple text file. ```robotframework *** Settings *** Library AllureLibrary *** Test Cases *** File Attachment Attach File ./my_file.txt ``` -------------------------------- ### Running Behave with Allure Testplan (PowerShell) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/testplan.rst Command to run Behave tests with the Allure formatter on Windows, setting the ALLURE_TESTPLAN_PATH environment variable using PowerShell syntax. ```powershell $Env:ALLURE_TESTPLAN_PATH = "./testplan.json" behave -f allure_behave.formatter:AllureFormatter -f pretty -o allure-results ``` -------------------------------- ### Defining Behave Step Implementation Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/testplan.rst Provides a simple Python step implementation for the "noop" step used in the Gherkin feature files. ```python from behave import given @given("noop") def step_impl(context): pass ``` -------------------------------- ### Defining Nested Allure Steps in Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/step/step.rst Shows how to create nested steps using multiple `with allure.step(...)` context managers. Steps are nested based on the context manager hierarchy. ```python def test_nested_steps(): with allure.step("grand parent step"): with allure.step("parent step"): passed_step() ``` -------------------------------- ### Use Allure Robot Framework Listener with Custom Output Directory Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/README.md Runs a Robot Framework test suite with the Allure listener, specifying a custom directory for the Allure results using a listener argument. ```Shell $ robot --listener allure_robotframework:/set/your/path/here ./my_robot_test ``` -------------------------------- ### Use Allure Robot Framework Listener with Pabot Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/README.md Runs a Robot Framework test suite in parallel using the pabot library, with the Allure listener enabled to collect results. ```Shell $ pabot --listener allure_robotframework ./my_robot_test ``` -------------------------------- ### Using Automatic Attachment Wrapper in Robot Framework Suite Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/attachment.rst This Robot Framework suite demonstrates how to use the Python wrapper for automatic attachments. By importing both the wrapper and the target library (SeleniumLibrary), calls to the target library's methods (like `Capture Page Screenshot`) will trigger the automatic attachment logic in the wrapper. ```robotframework *** Settings *** Library SeleniumLibrary Library ./selenium_wrapper.py *** Test Cases *** Automatic Screenshot Attachment Open Browser https://localhost:443 Chrome Capture Page Screenshot [Teardown] Close Browser ``` -------------------------------- ### Importing Allure Library in Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/step/step_placeholder.rst Imports the necessary 'allure' library to use its decorators and functions for test reporting. ```python import allure ``` -------------------------------- ### Scenarios for Dynamic Description in Behave Hooks (Gherkin) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/description.rst This Gherkin snippet defines two scenarios intended to demonstrate adding descriptions dynamically from Behave hooks (`before_scenario` and `after_scenario`). Both scenarios use the simple 'Given noop' step. ```gherkin Feature: Allure description for behave tests Scenario: Description from the before_scenario hook Given noop Scenario: Description from the after_scenario hook Given noop ``` -------------------------------- ### Apply Allure Tags to All Tests via Test Tags Setting Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/label.rst Illustrates using the `Test Tags` setting in the `*** Settings ***` section to automatically apply a specified Allure tag (e.g., `feature`) to all test cases within the file. ```robotframework *** Settings *** Test Tags allure.feature:Allure labels support *** Test Cases *** Test with two BDD-labels [Tags] allure.story:RF tags as allure labels No Operation ``` -------------------------------- ### Creating a Python Wrapper for Automatic Allure Attachments Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/attachment.rst This Python class acts as a Robot Framework library wrapper. It intercepts calls to another library (like SeleniumLibrary) and automatically attaches generated files (like screenshots) to the Allure report using the `allure.attach.file` function. ```python import allure from robot.libraries.BuiltIn import BuiltIn class SeleniumWrapper: ROBOT_LIBRARY_SCOPE = "TEST SUITE" ROBOT_LISTENER_API_VERSION = 2 def __init__(self): self.ROBOT_LIBRARY_LISTENER = self def _start_suite(self, name, attrs): BuiltIn().set_library_search_order(__name__) def capture_page_screenshot(self, *args, **kwargs): target_lib = BuiltIn().get_library_instance('SeleniumLibrary') path = target_lib.capture_page_screenshot(*args, **kwargs) allure.attach.file( path, name="page", attachment_type=allure.attachment_type.JPG ) return path selenium_wrapper = SeleniumWrapper ``` -------------------------------- ### Defining Inline Allure Step in Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/step/step.rst Demonstrates how to define an inline step within a test function using a `with allure.step(...)` context manager. Actions inside the `with` block are associated with this step. ```python def test_inline_step(): with allure.step("inline step"): pass ``` -------------------------------- ### Use Python Library with Allure Tags in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/tag.rst Shows how to import and use a Python library containing Allure tag logic within a Robot Framework test case, allowing the tags applied in the library functions to be associated with the test result. ```robotframework *** Settings *** Library ./my_lib.py *** Test Cases *** Stateful External Legacy Test Download Service List ``` -------------------------------- ### Apply Explicit Allure Tags in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/tag.rst Demonstrates how to explicitly apply Allure tags using the special Robot Framework tag syntax 'allure.label.tag:' or its shorter form 'allure.tag:'. ```robotframework *** Test Cases *** Explicit External Test [Tags] allure.label.tag:explicit allure.tag:extrenal No Operation ``` -------------------------------- ### Applying Manual Label with Decorator (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/manual/allure_manual.rst Demonstrates how to mark a test function as manual using the `@allure.manual` decorator. This is the standard way to statically label a test. Requires importing the `allure` library. ```python @allure.manual def test_manual(): pass ``` -------------------------------- ### Importing Allure Library - Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/link/link.rst Imports the necessary `allure` library to use its decorators and functions for test reporting. ```python import allure ``` -------------------------------- ### Allure Testplan JSON File Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/testplan.rst A JSON file defining an Allure testplan. It specifies which tests to include for execution based on their selector (name) or Allure ID. ```json { "version":"1.0", "tests": [ { "selector": "Testplan.Selected by Name" }, {"id": "1008"} ] } ``` -------------------------------- ### Importing Allure Library in Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/step/step.rst Imports the necessary `allure` library to use its functionalities like `allure.step`. This is a prerequisite for defining steps. ```python import allure ``` -------------------------------- ### Integrating Allure Behave with behave-parallel Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/README.md Shows how to integrate allure-behave when using behave-parallel by calling the allure_report hook directly within the environment.py file, providing the path to the result directory. ```python from allure_behave.hooks import allure_report ### your code allure_report("path/to/result/dir") ``` -------------------------------- ### Adding Description from Docstring (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/description/description.rst Shows how Allure can automatically pick up the description for a test case from the function's docstring. This is an alternative to using explicit decorators. ```python def test_docstring_description(): """ Docstring """ ``` -------------------------------- ### Adding Dynamic Description in Behave Step Definition (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/description.rst This Python step definition demonstrates how to dynamically add a description to an Allure report using `allure.dynamic.description()`. This method is useful for including runtime information in the test description, applied here within a Behave step. ```python from behave import given import allure @given("description is provided in a step definition") def step_impl(context): allure.dynamic.description( "This scenario has a description specified by the step definition" ) ``` -------------------------------- ### Call Python Library Function to Add Dynamic Allure Links in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/link.rst Shows a Robot Framework test case that imports a Python library and calls a keyword defined in that library. The Python keyword (Add Three Links) is responsible for adding dynamic Allure links to the test result. ```robotframework *** Settings *** Library ./my_lib.py *** Test Cases *** Allure Link Decorators and Functions Add Three Links ``` -------------------------------- ### Add Custom Allure Label via Robot Framework Tag Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/label.rst Demonstrates how to add a custom Allure label to a specific test case by applying a tag in the format `allure.label.:`. ```robotframework *** Test Cases *** Test authored by John Doe [Tags] allure.label.author:John Doe No Operation ``` -------------------------------- ### Attaching Plain Text in Allure Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/attachment/attachment.rst Demonstrates attaching simple plain text content to an Allure report using the `allure.attach` function with default parameters. Requires the `allure` library. ```Python import allure def test_attach_body_with_default_kwargs(): allure.attach("Some content in plain text") ``` -------------------------------- ### Adding Dynamic Description in Behave Hooks (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/description.rst This Python snippet shows how to add dynamic descriptions to scenarios from Behave hooks (`before_scenario` and `after_scenario`) defined in `environment.py`. It uses `allure.dynamic.description()` conditionally based on the scenario name. ```python 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" ) ``` -------------------------------- ### Applying Manual Label Dynamically (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/manual/allure_manual.rst Shows how to dynamically set the manual label within a test function using `allure.dynamic.manual()`. This is useful for conditional labeling or when the label cannot be applied via a decorator. Requires importing the `allure` library. ```python def test_manual_dynamic(): allure.dynamic.manual() ``` -------------------------------- ### Defining Reusable Allure Step with Decorator in Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/step/step.rst Shows how to define a reusable step by decorating a function with `@allure.step`. Calling this function will register it as a step in the Allure report. ```python @allure.step def passed_step(): pass ``` -------------------------------- ### Importing Allure and Pytest (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/severity/dynamic_severity.rst Imports the necessary `allure` library for generating reports and `pytest` as the test execution framework. ```python import allure import pytest ``` -------------------------------- ### Combining Static and Dynamic Links Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/link/dynamic_link.rst Demonstrates adding multiple static 'issue' links using `@allure.issue` decorators and a dynamic custom link using `allure.dynamic.link` within the test function. ```python @allure.issue("issues/24") @allure.issue("issues/132") def test_all_links_together(): allure.dynamic.link("allure", name="QAMETA", link_type="docs") ``` -------------------------------- ### Defining and Calling Allure Step in Python Class Method Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/step/step_placeholder.rst Defines a class with a method decorated with '@allure.step'. The step title uses a mix of positional ({1}) and keyword ({second}) placeholders. A test method within the same class calls this step method, demonstrating placeholder usage in a class context. ```python class TestClass(object): @allure.step("Class method step with {1} and {second}") def class_method_step_with_placeholder(self, first, second="second"): pass def test_class_method_as_step(self): self.class_method_step_with_placeholder("first") ``` -------------------------------- ### Adding Description in Gherkin Feature File Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/description.rst This Gherkin snippet demonstrates how to add a multi-line description directly within a Scenario block in a .feature file for Behave tests. The text following the Scenario title and before the first step is treated as the scenario description by Allure. ```gherkin Feature: Allure description for behave tests Scenario: Description from a .feature file This scenario has a description. This description spans across multiple lines. Given noop ``` -------------------------------- ### Calling Allure Step with Positional Args in Python Test Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/step/step_placeholder.rst A test function that calls the 'step_with_args_in_placeholder' function, demonstrating how the arguments passed will populate the placeholders in the Allure step title. ```python def test_step_with_args_in_placeholder(): step_with_args_in_placeholder("first", "second") ``` -------------------------------- ### Add Built-in Allure Labels via Robot Framework Tags Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/label.rst Shows how to add built-in Allure labels like `id` and `story` to a test case using a shorter tag format `allure.:`. ```robotframework *** Test Cases *** Test with the pinned ID [Tags] allure.id:1008 ... allure.story:RF tags as allure labels No Operation ``` -------------------------------- ### Add Unnamed Allure Link via Robot Framework Tag Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/link.rst Demonstrates adding a generic link to a Robot Framework test case using the allure.link: tag format. The URL itself will be used as the link text in the Allure report. ```robotframework *** Test Cases *** Allure Plain Link [Tags] allure.link:https://github.com/allure-framework/allure-python No Operation ``` -------------------------------- ### Adding String Description with Allure Decorator (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/description/description.rst Demonstrates how to use the `@allure.description` decorator to add a simple string description to an Allure test function. The description string is provided directly as an argument to the decorator. ```python import allure @allure.description("""Test description""") def test_description(): pass ``` -------------------------------- ### Scenario for Dynamic Description in Step Definition (Gherkin) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/description.rst This Gherkin snippet defines a scenario where the test description will be added dynamically from within its step definition. It uses a single 'Given' step that triggers the dynamic description logic. ```gherkin Feature: Allure description for behave tests Scenario: Description from a step definition Given description is provided in a step definition ``` -------------------------------- ### Running Behave with Allure Formatter (Hide Excluded) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/testplan.rst Command to run Behave tests with the Allure formatter, adding an argument to hide tests excluded by the testplan from the Allure report. ```shell behave -f allure_behave.formatter:AllureFormatter -D AllureFormatter.hide_excluded=True -f pretty -o allure-results ``` -------------------------------- ### Include External Requirements Files Source: https://github.com/allure-framework/allure-python/blob/master/allure-nose2/requirements.txt Uses the -r option to recursively include dependencies listed in other requirements files. This helps in organizing and reusing sets of dependencies. ```Requirements -r ../requirements/testing.txt -r ../requirements/linting.txt -r ../requirements/testing/allure-nose2.txt ``` -------------------------------- ### Add Allure Link to Feature using Gherkin Tag Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/link.rst Shows how to apply an Allure link tag (`@allure.link.:`) at the feature level in a Gherkin file, associating the link with all scenarios within that feature. ```gherkin @allure.link.homepage:https://qameta.io Feature: Allure link support Scenario: Scenario with the link to the homepage Given noop Scenario: Another scenario with the link to the homepage Given noop ``` -------------------------------- ### Calling Allure Step with Keyword Args in Python Test Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/step/step_placeholder.rst A test function that calls the 'step_with_kwargs_in_placeholder' function, demonstrating how the keyword arguments passed will populate the placeholders in the Allure step title. Only one keyword argument is explicitly passed. ```python def test_step_with_kwargs_in_placeholder(): step_with_kwargs_in_placeholder(first="1") ``` -------------------------------- ### Defining Behave Feature with Fullname Selection (2) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/testplan.rst Defines a second Behave feature file with two scenarios, intended for selection/deselection using the full scenario name in an Allure testplan. ```gherkin Feature: Allure testplan support 2 Scenario: Scenario selection 2 Given noop Scenario: Scenario deselection 2 Given noop ``` -------------------------------- ### Attaching XML and Plain Text Content in Allure Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/attachment/attachment.rst Shows how to attach different types of content, specifically XML and plain text, to an Allure report. It uses `allure.attach` with explicit `name` and `attachment_type` parameters for XML and default parameters for plain text. Requires the `allure` library. ```Python def test_attach_body(): xml_content = """ ... """ allure.attach(xml_content, name='some attachment name', attachment_type=allure.attachment_type.XML) allure.attach("Some content in plain text") ``` -------------------------------- ### Setting Allure Suite Labels with Decorators (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/suite/custom_suite.rst Demonstrates how to use the `@allure.parent_suite`, `@allure.suite`, and `@allure.sub_suite` decorators to assign custom suite labels to a test method in Allure Python. ```Python >>> import allure >>> class TestCustomSuites: ... @allure.parent_suite("parent suite name") ... @allure.suite("suite name") ... @allure.sub_suite("sub suite name") ... def test_custom_suites(self): ... pass ``` -------------------------------- ### Add Named Allure Link via Robot Framework Tag Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/link.rst Shows how to add a generic link with custom text to a Robot Framework test case using the allure.link.: tag format. The specified text will appear in the Allure report instead of the URL. ```robotframework *** Test Cases *** Allure Plain Link [Tags] allure.link.allure-python:https://github.com/allure-framework/allure-python No Operation ``` -------------------------------- ### Partial Allure Tag Application Due to Failure in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/tag.rst Illustrates that if a test step fails, subsequent tag modifications using keywords like 'Set Tags' or 'Remove Tags' will not be executed, potentially resulting in an incomplete set of Allure tags. ```robotframework *** Test Cases *** Supposed to Be an Isolated Test [Documentation] But ends up being a distributed one. [Tags] distributed Fail Unexpected failure Set Tags isolated Remove Tags distributed ``` -------------------------------- ### Adding Unicode Description from Docstring (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/description/description.rst Illustrates that Allure also supports picking up descriptions from docstrings containing Unicode characters, demonstrating compatibility with non-ASCII text. ```python def test_unicode_docstring_description(): """ Докстринг в юникоде """ ``` -------------------------------- ### Apply Dynamic Allure Tags in Robot Framework Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/tag.rst Shows how Allure tags can be modified dynamically during test execution using Robot Framework's built-in keywords like 'Set Tags' and 'Remove Tags'. The conversion happens after the test case completes. ```robotframework *** Test Cases *** Isolated Test [Tags] distributed Set Tags isolated Remove Tags distributed ``` -------------------------------- ### Apply Allure Tags in Robot Framework Library (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/tag.rst Illustrates how to add Allure tags to the current test result from within a Python test library using the '@allure.tag' decorator for functions or the 'allure.dynamic.tag' function for dynamic tagging during execution. ```python import allure @allure.tag("external") def connect_to_external_api(): pass @allure.tag("legacy") def download_service_list(): connect_to_external_api() allure.dynamic.tag("stateful") ``` -------------------------------- ### Defining Allure Step with Keyword Arg Placeholders in Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/step/step_placeholder.rst Defines a function decorated with '@allure.step' where the step title uses keyword placeholders ({first}, {second}) to include the function's keyword arguments in the report title. Default values are provided for the arguments. ```python @allure.step("Step with two kwargs: {first} and {second}") def step_with_kwargs_in_placeholder(first="first", second="second"): pass ``` -------------------------------- ### Defining Behave Feature with Allure ID (2) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/testplan.rst Defines a second Behave feature file with scenarios tagged with Allure `as_id` labels, intended for selection/deselection using IDs in an Allure testplan. ```gherkin Feature: Allure testplan support 2 @allure.label.as_id:1006 Scenario: Scenario selection 2 Given noop @allure.label.as_id:1007 Scenario: Scenario deselection 2 Given noop ``` -------------------------------- ### Calling Reusable Allure Step in Python Test Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/step/step.rst Illustrates how to call a previously defined reusable step (`passed_step`) from within a test function. This registers the reusable step execution in the report. ```python def test_reusable_step(): passed_step() ``` -------------------------------- ### Setting Allure Suite Labels Dynamically (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/suite/custom_suite.rst Shows how to use the `allure.dynamic.parent_suite`, `allure.dynamic.suite`, and `allure.dynamic.sub_suite` functions to set custom suite labels programmatically within a test method in Allure Python. ```Python >>> import allure >>> class TestCustomDynamicSuites: ... def test_custom_dynamic_suites(self): ... allure.dynamic.parent_suite("parent suite name") ... allure.dynamic.suite("suite name") ... allure.dynamic.sub_suite("sub suite name") ``` -------------------------------- ### Allure Testplan JSON (ID Selector) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/testplan.rst Defines an Allure testplan JSON file that selects specific scenarios based on their Allure `as_id` labels. ```json { "version":"1.0", "tests": [ {"id": "1004"}, {"id": "1006"} ] } ``` -------------------------------- ### Defining Behave Feature with Fullname Selection (1) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/testplan.rst Defines a Behave feature file with two scenarios, intended for selection/deselection using the full scenario name in an Allure testplan. ```gherkin Feature: Allure testplan support Scenario: Scenario selection Given noop Scenario: Scenario deselection Given noop ``` -------------------------------- ### Add Dynamic Allure Links from Python Library Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/link.rst Defines a Python function within a test library that uses allure.dynamic.link, allure.dynamic.issue, and allure.dynamic.testcase to add various link types to the currently running test case programmatically. ```python import allure def add_three_links(): allure.dynamic.link("https://github.com/allure-framework/allure-python", name="allure-python") allure.dynamic.issue("https://github.com/allure-framework/allure-python/issues/1", name="ISSUE-1") allure.dynamic.testcase("https://my-tms/test-cases/1", name="TESTCASE-1") ``` -------------------------------- ### Allure Testplan JSON (Fullname Selector) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/testplan.rst Defines an Allure testplan JSON file that selects specific scenarios based on their full feature and scenario names. ```json { "version":"1.0", "tests": [ { "selector": "Allure testplan support: Scenario selection" }, { "selector": "Allure testplan support 2: Scenario selection 2" } ] } ``` -------------------------------- ### Applying Single Allure BDD Labels (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/bdd/bdd_label.rst Demonstrates how to apply a single value for each BDD label decorator (@allure.epic, @allure.feature, @allure.story) to a Python test function using the Allure framework. These labels help categorize tests based on Epic, Feature, and Story for reporting. ```Python @allure.epic("My epic") @allure.feature("My feature") @allure.story("My story") def test_single_bdd_label(): pass ``` -------------------------------- ### Importing Allure Library (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/suite/module_level_custom_suite.rst Imports the necessary `allure` library to access its functionalities, such as defining test suites. ```python import allure ``` -------------------------------- ### Add Allure Link to Scenario using Gherkin Tag Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/link.rst Demonstrates how to add a custom link to a specific test scenario in a Gherkin feature file using the `@allure.link.:` tag. ```gherkin Feature: Allure link support @allure.link.report:https://qameta.io/allure-report/ Scenario: Scenario with the link to the allure report website Given noop ``` -------------------------------- ### Add Allure Issue Link via Robot Framework Tag Source: https://github.com/allure-framework/allure-python/blob/master/allure-robotframework/examples/link.rst Illustrates adding an issue link to a Robot Framework test case using the allure.issue.: tag format. This links the test result to a specific issue tracker entry. ```robotframework *** Test Cases *** Allure Issue Link [Tags] allure.issue.ISSUE-1:https://github.com/allure-framework/allure-python/issues/1 No Operation ``` -------------------------------- ### Add Allure Link Dynamically in Python Hook Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/link.rst Demonstrates how to dynamically add a custom Allure link to a test case from a Behave `before_scenario` hook using `allure.dynamic.link()`. ```python import allure def before_scenario(context, scenario): allure.dynamic.link( "https://qameta.io/allure-report/", name="Allure Report" ) ``` -------------------------------- ### Defining Allure Step with Positional Arg Placeholders in Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/step/step_placeholder.rst Defines a function decorated with '@allure.step' where the step title uses positional placeholders ({0}, {1}) to include the function's arguments in the report title. ```python @allure.step("Step with two args: {0} and {1}") def step_with_args_in_placeholder(first, second): pass ``` -------------------------------- ### Adding HTML Description with Allure Decorator (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/description/description.rst Illustrates using the `@allure.description_html` decorator to add an HTML description to an Allure test function. The HTML content is passed as a string argument and will be rendered in the report. ```python import allure @allure.description_html("""

Html test description

""") def test_description_html(): pass ``` -------------------------------- ### Add Allure Issue/TMS Links using Gherkin Tags Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/link.rst Illustrates the use of specialized Gherkin tags, `@allure.issue:` and `@allure.tms:`, to link test scenarios to external issue trackers or test management systems. ```gherkin Feature: Allure link support @allure.issue:https://github.com/allure-framework/allure-python/issues/1 Scenario: Scenario associated with the issue Given noop @allure.tms:https://qameta.io/#features Scenario: Scenario associated with the TMS test case Given noop ``` -------------------------------- ### Applying Multiple Allure BDD Labels (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/bdd/bdd_label.rst Shows how to apply multiple values for Allure BDD labels (@allure.epic, @allure.feature, @allure.story) to a Python test function by providing comma-separated strings to the decorators. This allows a single test to be associated with multiple epics, features, or stories in the Allure report. ```Python @allure.epic("My epic", "Another epic") @allure.feature("My feature", "Another feature", "One more feature") @allure.story("My story", "Alternative story") def test_multiple_bdd_label(): pass ``` -------------------------------- ### Defining Behave Feature with Allure ID (1) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/testplan.rst Defines a Behave feature file with scenarios tagged with Allure `as_id` labels, intended for selection/deselection using IDs in an Allure testplan. ```gherkin Feature: Allure testplan support @allure.label.as_id:1004 Scenario: Scenario selection Given noop @allure.label.as_id:1005 Scenario: Scenario deselection Given noop ``` -------------------------------- ### Importing Allure Library (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/severity/module_severity.rst Imports the necessary `allure` library to use its functionalities, such as severity marking, within a Python test file. ```python import allure ``` -------------------------------- ### Attaching a File in Allure Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/attachment/attachment.rst Illustrates how to attach an existing file to an Allure report using the `allure.attach.file` function. It uses the `__file__` variable to attach the current script file. Requires the `allure` library. ```Python def test_attach_file(): allure.attach.file(__file__) # this file path ``` -------------------------------- ### Feature File for Data Attachment (Gherkin) Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/attachment.rst Defines a feature and scenario for testing Allure data attachments within behave step definitions. It outlines the steps that will trigger the attachment creation. ```gherkin Feature: Allure attachments in behave tests\ Scenario: Data attachment from step definitions\ Given a step that adds a named attachment\ And a step that adds a typed named attachment ``` -------------------------------- ### Adding Parameterized Dynamic Issue Links Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/link/dynamic_link.rst Uses `pytest.mark.parametrize` to run a test multiple times with different link values, dynamically adding an 'issue' link for each run using `allure.dynamic.issue`. ```python @pytest.mark.parametrize('link', ["issues/24", "issues/132"]) def test_parametrize_dynamic_link(link): allure.dynamic.issue(link) ``` -------------------------------- ### Adding Custom Labels with allure.label (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/custom/custom_label.rst This snippet demonstrates how to apply custom labels to a test function using the `allure.label` decorator. It assigns the labels "desktop" and "mobile" under the "Application" type to the `test_custom_label` function, which will be reflected in the Allure report. ```python import allure @allure.label("Application", "desktop", "mobile") def test_custom_label(): pass ``` -------------------------------- ### Applying Allure Labels to Python Tests Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/custom/select_tests_by_label.rst Demonstrates how to apply custom labels to test functions using the `@allure.label` decorator in Python. Labels consist of a name and one or more values. Tests can have multiple labels. ```Python import allure @allure.label("Application", "desktop") def test_custom_label_one(): pass @allure.label("Application", "mobile") def test_custom_label_another(): pass @allure.label("Application", "mobile", "desktop") def test_custom_label_both(): pass @allure.label("layer", "api") def test_layer_label(): pass def test_no_labels(): pass ``` -------------------------------- ### Attach Context in Pytest Fixture Finalizer (Python) Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/attachment/attachment_fixture.rst This snippet demonstrates attaching context during the teardown phase of a pytest fixture. It defines a finalizer function that attaches the current file path using `allure.attach` and registers it with `request.addfinalizer`. ```python import pytest import allure @pytest.fixture def fixture_with_attachment_in_finalizer(request): def finalizer(): allure.attach(__file__) request.addfinalizer(finalizer) def test_fixture_finalizer_attachment(fixture_with_attachment_in_finalizer): pass ``` -------------------------------- ### Adding Parametrized Dynamic BDD Labels in Allure Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/bdd/dynamic_bdd_label.rst Illustrates how to apply dynamic BDD labels (feature, epic, story) in a parametrized pytest function using allure.dynamic. The label values are passed as parameters to the test function. Requires allure-python and pytest. ```Python @pytest.mark.parametrize('feature, epic, story', [('first feature', 'first epic', 'first story'), ('second feature', 'second epic', 'second story')]) def test_parametrized_dynamic_labels(feature, epic, story): allure.dynamic.feature(feature) allure.dynamic.epic(epic) allure.dynamic.story(story) ``` -------------------------------- ### Defining Class Method as Allure Step in Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/step/step.rst Demonstrates how to use the `@allure.step` decorator on a class method to make it a reusable step. The method can then be called from a test method within the same class. ```python class TestClass(object): @allure.step("class method as step") def class_method(self): pass def test_class_method_as_step(self): self.class_method() ``` -------------------------------- ### Adding Dynamic BDD Labels in Allure Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/label/bdd/dynamic_bdd_label.rst Shows how to add dynamic BDD labels (feature, epic, story) to an Allure test using allure.dynamic. It also includes static labels defined via decorators, which are overridden or supplemented by dynamic labels. Requires allure-python and pytest. ```Python import allure import pytest @allure.feature('first feature') @allure.epic('first epic') @allure.story('first story') def test_dynamic_labels(): allure.dynamic.feature('second feature') allure.dynamic.epic('second epic') allure.dynamic.story('second story') ``` -------------------------------- ### Applying Multiple Allure Tags in Gherkin Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/tag.rst You can apply multiple Gherkin tags to both features and scenarios. All tags applied to a feature and its scenario will be added to the corresponding Allure test case. ```Gherkin @node-1 @node-2 Feature: Allure tag support @node-3 @node-4 Scenario: Applying multiple tags Given noop ``` -------------------------------- ### Updating Allure Description Dynamically in Python Source: https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/description/dynamic_description.rst This snippet demonstrates how to use `allure.dynamic.description` and `allure.dynamic.description_html` inside a test function to override the description initially set by the `@allure.description` or `@allure.description_html` decorators. ```Python >>> import allure >>> @allure.description("Initial description") ... def test_dynamic_description(): ... allure.dynamic.description("Actual description") >>> @allure.description_html("

Initial HTML description

") ... def test_dynamic_description_html(): ... allure.dynamic.description_html("

Actual HTML description

") ``` -------------------------------- ### Add Allure Issue Link Dynamically in Python Step Source: https://github.com/allure-framework/allure-python/blob/master/allure-behave/examples/link.rst Shows how to dynamically add an Allure issue link to a test case from within a Behave step definition using `allure.dynamic.issue()`. ```python import allure from behave import given @given("a link is associated with this test case") def step_impl(context): allure.dynamic.issue( "https://github.com/allure-framework/allure-python/issues/1", "Skip None and empty values in json" ) ```