Search code examples
pythonautomationpytestpython-decoratorsallure

How can I insert some variable into allure decorators?


I need to pass some variable into allure decorator, because I want to add some test data to my reports, how can I do that?

import allure


@allure.title("Do that")
@allure.step("Make sure that some_param == {I NEED TO PASS expected HERE}")
def test_1(data_for_test):
   expected, real = data_for_test
   assert expected == real

Also how can I insert values into alure decorators, using this?

def some_func():
    some_var = "qwe"
    with allure.step("Some text with some {some_var}"):
        pass

Solution

  • You can use allure.dynamic to access allure functions

    def test_1(data_for_test):
        expected, real = data_for_test
        allure.dynamic.description(f'Make sure that some_param == {expected}')
        assert expected == real
    

    Use f-string to insert the data to allure.step as well

    def some_func():
        some_var = "qwe"
        with allure.step(f"Some text with some {some_var}"):
            pass