Skip to content

Support template for display name (fixes #196) #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions allure-pytest/src/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,27 @@ def pytest_runtest_protocol(self, item, nextitem):
self.allure_logger.start_group(group_uuid, group)
self.allure_logger.update_group(group_uuid, children=uuid)

test_case = TestResult(name=allure_name(item), uuid=uuid)
test_case.description = allure_description(item)
test_case.descriptionHtml = allure_description_html(item)
params = item.callspec.params if hasattr(item, 'callspec') else {}

self.allure_logger.schedule_test(uuid, test_case)
yield

for name, value in item.callspec.params.items() if hasattr(item, 'callspec') else ():
test_result = self.allure_logger.get_test(uuid)
if test_result:
test_result.parameters.append(Parameter(name, represent(value)))
test_result = TestResult(name=allure_name(item, params), uuid=uuid)
test_result.description = allure_description(item)
test_result.descriptionHtml = allure_description_html(item)
test_result.fullName = allure_full_name(item)
test_result.historyId = md5(test_result.fullName)
test_result.parameters.extend([Parameter(name=name, value=represent(value)) for name, value in params.items()])

test_case.labels.extend([Label(name=name, value=value) for name, value in allure_labels(item)])
test_case.labels.extend([Label(name=LabelType.TAG, value=value) for value in pytest_markers(item)])
test_case.labels.append(Label(name=LabelType.HOST, value=self._host))
test_case.labels.append(Label(name=LabelType.THREAD, value=self._thread))
test_case.labels.append(Label(name=LabelType.FRAMEWORK, value='pytest'))
test_case.labels.append(Label(name=LabelType.LANGUAGE, value=platform_label()))
self.allure_logger.schedule_test(uuid, test_result)

test_case.links += [Link(link_type, url, name) for link_type, url, name in allure_links(item)]
yield

test_case.fullName = allure_full_name(item)
test_case.historyId = md5(test_case.fullName)
test_case.labels.append(Label('package', allure_package(item)))
test_result.labels.extend([Label(name=name, value=value) for name, value in allure_labels(item)])
test_result.labels.extend([Label(name=LabelType.TAG, value=value) for value in pytest_markers(item)])
test_result.labels.append(Label(name=LabelType.HOST, value=self._host))
test_result.labels.append(Label(name=LabelType.THREAD, value=self._thread))
test_result.labels.append(Label(name=LabelType.FRAMEWORK, value='pytest'))
test_result.labels.append(Label(name=LabelType.LANGUAGE, value=platform_label()))
test_result.labels.append(Label(name='package', value=allure_package(item)))
test_result.links.extend([Link(link_type, url, name) for link_type, url, name in allure_links(item)])

uuid = self._cache.pop(item.nodeid)
self.allure_logger.close_test(uuid)
Expand Down
4 changes: 2 additions & 2 deletions allure-pytest/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def allure_package(item):
return path.replace('/', '.')


def allure_name(item):
def allure_name(item, parameters):
name = escape_name(item.name)
title = allure_title(item)
return title if title else name
return title.format(**parameters) if title else name


def allure_full_name(item):
Expand Down
55 changes: 55 additions & 0 deletions allure-pytest/test/display_name/display_name_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
import pytest
import allure


@allure.title("A some test title")
def test_display_name():
"""
>>> allure_report = getfixture('allure_report')
>>> assert_that(allure_report,
... has_test_case('test_display_name',
... has_title("A some test title")
... )
... )
"""


@allure.title("A some test title with param {param}")
@pytest.mark.parametrize('param', [False])
def test_display_name_template(param):
"""
>>> allure_report = getfixture('allure_report')
>>> assert_that(allure_report,
... has_test_case('test_display_name_template[False]',
... has_title("A some test title with param False")
... )
... )
"""
assert param


@allure.title(u"Тест с шаблоном и параметром: {param}")
@pytest.mark.parametrize('param', [False])
def test_unicode_display_name_template(param):
u"""
>>> allure_report = getfixture('allure_report')
>>> assert_that(allure_report,
... has_test_case('test_unicode_display_name_template[False]',
... has_title(u"Тест с шаблоном и параметром: False")
... )
... )
"""
assert param


@allure.title(u"Лунтик")
def test_unicode_display_name():
u"""
>>> allure_report = getfixture('allure_report')
>>> assert_that(allure_report,
... has_test_case('test_unicode_display_name',
... has_title(u"Лунтик")
... )
... )
"""
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@


@allure.title("A some test tile")
def test_dynamic_title():
def test_dynamic_display_name():
"""
>>> allure_report = getfixture('allure_report')
>>> assert_that(allure_report,
... has_test_case('test_dynamic_title',
... has_test_case('test_dynamic_display_name',
... has_title("It is renamed test")
... )
... )
Expand Down
28 changes: 0 additions & 28 deletions allure-pytest/test/title/test_title_test.py

This file was deleted.