pythontestingautomated-testspytestallure

Allure custom labels won’t show up in the final report (pytest, allure)


Premise

Allure documentation says that I can add labels.

import allure from allure_commons.types 
import LabelType 

@allure.label(LabelType.LANGUAGE, "python") 
@allure.label(LabelType.FRAMEWORK, "pytest") 
def test_authentication():

"It can be a constant from the LabelType class or any other string."

So I assume this should work:

import allure 

@allure.label("any other string", "python") 
@allure.label("another any other string", "pytest") 
def test_authentication():

Problem

Although, when I add my any other string custom label via @allure.label(), it won’t show up in the report.

For example:

# root_dir/test.py  

import allure  

@allure.label('Area', 'someArea') 
@allure.label('Component', 'someComponent') 
@allure.label('Relevance', 'someVersion') 
def test_smth()

Then I run the test; point to reports/ to save the report; and open it in the browser:

pytest -v -s --alluredir reports

allure serve reports

And there’s no trace of my custom labels in the report. And no corresponding tag or element or something else in the report’s HTML.

At the very same time, when I open *-result.json in my Allure report directory reports/, I see my custom labels there:

"labels": [{"name": "Area", "value": "someArea"}, {"name": "Component", "value": "someComponent"}, {"name": "Relevance", "value": "someVersion"}

BTW

The example from the documentation doesn’t show up in the final report:

@allure.label(LabelType.LANGUAGE, "python") 

What actually shows up in the final report:

@allure.title() 
@allure.description() 
@allure.severity() 
@allure.testcase() 
@allure.story() 
@allure.featur() 
@allure.tag 

What else I tried:

Making a separate place to keep my labels

# root_dir/custom_allure_labels.py  

import allure 
 
def area(value):     
    return allure.label('Area', value)  

def component(value):     
    return allure.label('Component', value)  

def relevance(value):     
    return allure.label('Relevance', value)  
# root_dir/test.py 

import allure  
from custom_allure_labels import area, component, relevance  
 
@area('someArea')  
@component('someComponent')  
@relevance('someVersion')  
def test_smth()

No result.

All the same + adding properties

# root_dir/allure.properties    

allure.label.Area=Area  
allure.label.Component=Component  
allure.label.Relevance=Relevance
# root_dir/custom_allure_labels.py  

import allure 
from allure_commons.types import LabelType  

def area(value):     
    allure.label(LabelType.CUSTOM_LABEL_1, value)     
        return allure.label('Area', value)  
def component(value):     
    allure.label(LabelType.CUSTOM_LABEL_2, value)     
        return allure.label('Component', value)  
def relevance(value):     
    allure.label(LabelType.CUSTOM_LABEL_3, value)     
        return allure.label('Relevance', value) 
# root_dir/test.py  

import allure 
from custom_allure_labels import area, component, relevance  

@area('someArea') 
@component('someComponent') 
@relevance('someVersion') 
def test_smth()

No result.

Similar but adding a `decorator` func

# root_dir/custom_allure_labels.py  

import allure  

def custom_allure_labels(area, component, relevance):     
    def decorator(func):         
        allure.label('Area', area)(func)         
        allure.label('Component', component)(func)         
        allure.label('Relevance', relevance)(func)         
        return func     
    return decorator
# root_dir/test.py  

import allure 
from custom_allure_labels import area, component, relevance  

@custom_allure_labels(         
    area='someArea',         
    component='someComponent',         
    relevance='someVersion',     
    ) 
def test_smth()

Question

What is wrong with what I’m trying to do?

Is there a way to add custom attributes into `LabelType`?


Solution

  • Custom labels are not visible in the Allure Report but can be mapped to Custom Fields in Allure Testops and used for advanced filtering & grouping.

    You can find the list of labels that take effect in the Allure Report here: https://github.com/orgs/allure-framework/discussions/2059#discussioncomment-6616266