[*]python 3.12.2
[*]allure-pytest: 2.13.5
[*]allure-python-commons: 2.13.5
[*]pytest : 8.2.2
[*]allure CLI: 2.30.0
Предпосылка
В документации Allure указано, что я могу добавлять метки.
Код: Выделить всё
import allure from allure_commons.types
import LabelType
@allure.label(LabelType.LANGUAGE, "python")
@allure.label(LabelType.FRAMEWORK, "pytest")
def test_authentication():
Поэтому я предполагаю, что так и должно быть работа:
Код: Выделить всё
import allure
@allure.label("any other string", "python")
@allure.label("another any other string", "pytest")
def test_authentication():
Однако, когда я добавляю свою собственную метку любую другую строку через @allure.label(), он не будет отображаться в отчете.
Например:
Код: Выделить всё
# root_dir/test.py
import allure
@allure.label('Area', 'someArea')
@allure.label('Component', 'someComponent')
@allure.label('Relevance', 'someVersion')
def test_smth()
Код: Выделить всё
pytest -v -s --alluredir reports
Код: Выделить всё
allure serve reports
В то же время, когда я открываю *-result.json в моем каталоге отчетов Allure, report/ , я вижу там свои собственные метки:
Код: Выделить всё
"labels": [{"name": "Area", "value": "someArea"}, {"name": "Component", "value": "someComponent"}, {"name": "Relevance", "value": "someVersion"}
Пример из документации не отображается в итоговом отчете:
Код: Выделить всё
@allure.label(LabelType.LANGUAGE, "python")
Код: Выделить всё
@allure.title()
@allure.description()
@allure.severity()
@allure.testcase()
@allure.story()
@allure.featur()
@allure.tag
Создал отдельное место для хранения ярлыков
Код: Выделить всё
# 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()
Все то же самое + добавление свойств
Код: Выделить всё
# 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()
Аналогично, но добавлена функция декоратора
Код: Выделить всё
# 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()
Что не так с тем, что я пытаюсь сделать?
Есть ли способ добавить пользовательские атрибуты в LabelType?
Подробнее здесь: https://stackoverflow.com/questions/788 ... est-allure