-
python 3.12.2
-
allure-pytest: 2.13.5
-
allure-python-commons: 2.13.5
-
pytest: 8.2.2
-
allure CLI: 2.30.0
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 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 this:
"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:
python @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`?
KD. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.