Skip to content
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
21 changes: 21 additions & 0 deletions allure-behave/features/description.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,24 @@ Feature: Description
"""
When I run behave with allure formatter
Then allure report has a scenario with name "Scenario with description"

Scenario: Dynamic description
Given feature definition
"""
Feature: Step status

Scenario: Scenario with passed step
Given simple passed step
"""
And hooks implementation
"""
import allure
import allure_commons

@allure_commons.fixture
def before_scenario(context, scenario):
allure.dynamic.description("Test description")
"""
When I run behave with allure formatter
Then allure report has a scenario with name "Scenario with passed step"
And scenario has description "Test description"
26 changes: 24 additions & 2 deletions allure-behave/features/link.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: Link

Scenario: Scenario issue link
Scenario: Scenario issue link
Given feature definition
"""
Feature: Step status
Expand All @@ -26,7 +26,6 @@ Feature: Link
Then allure report has a scenario with name "Scenario with passed step"
And scenario has "http://qameta.io" link


Scenario: Feature and scenario user link
Given feature definition
"""
Expand All @@ -41,3 +40,26 @@ Feature: Link
Then allure report has a scenario with name "Scenario with passed step"
And scenario has "http://qameta.io" link
And scenario has "http://example.com" link with type "issue"

Scenario: Dynamic link
Given feature definition
"""
Feature: Step status

Scenario: Scenario with passed step
Given simple passed step
"""
And hooks implementation
"""
import allure
import allure_commons

@allure_commons.fixture
def before_scenario(context, scenario):
allure.dynamic.link("http://qameta.io")
allure.dynamic.issue("http://example.com")
"""
When I run behave with allure formatter
Then allure report has a scenario with name "Scenario with passed step"
And scenario has "http://qameta.io" link
And scenario has "http://example.com" link with type "issue"
10 changes: 9 additions & 1 deletion allure-behave/features/steps/report_steps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functools import partial
from hamcrest import assert_that
from hamcrest import assert_that, contains_string
from hamcrest import not_
from allure_commons_test.report import has_test_case
from allure_commons_test.result import with_status
Expand All @@ -9,6 +9,7 @@
from allure_commons_test.result import has_status_details
from allure_commons_test.result import with_message_contains
from allure_commons_test.result import has_link
from allure_commons_test.result import has_description
from allure_commons_test.container import has_container
from allure_commons_test.container import has_before, has_after
from allure_commons_test.label import has_severity
Expand Down Expand Up @@ -149,3 +150,10 @@ def step_attachment(context, item):
context_matcher = getattr(context, item)
matcher = partial(context_matcher, has_attachment)
assert_that(context.allure_report, matcher())


@then(u'scenario has description "{description}"')
def step_description(context, description):
context_matcher = context.scenario
matcher = partial(context_matcher, has_description, contains_string(description))
assert_that(context.allure_report, matcher())
43 changes: 38 additions & 5 deletions allure-behave/src/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from allure_commons.utils import uuid4
from allure_commons.utils import now
from allure_commons.utils import platform_label
from allure_commons.types import LabelType, AttachmentType
from allure_commons.types import LabelType, AttachmentType, LinkType
from allure_commons.model2 import TestResult
from allure_commons.model2 import TestStepResult
from allure_commons.model2 import TestBeforeResult, TestAfterResult
from allure_commons.model2 import TestResultContainer
from allure_commons.model2 import Parameter, Label
from allure_commons.model2 import Parameter, Label, Link
from allure_behave.utils import scenario_parameters
from allure_behave.utils import scenario_name
from allure_behave.utils import scenario_history_id
Expand All @@ -33,6 +33,8 @@
class AllureListener(object):
def __init__(self, behave_config):
self.behave_config = behave_config
self.issue_pattern = behave_config.userdata.get('AllureFormatter.issue_pattern', None)
self.link_pattern = behave_config.userdata.get('AllureFormatter.link_pattern', None)
self.logger = AllureReporter()
self.current_step_uuid = None
self.current_scenario_uuid = None
Expand Down Expand Up @@ -100,9 +102,10 @@ def start_scenario(self, scenario):
test_case.description = '\n'.join(scenario.description)
test_case.parameters = scenario_parameters(scenario)

issue_pattern = self.behave_config.userdata.get('AllureFormatter.issue_pattern', None)
link_pattern = self.behave_config.userdata.get('AllureFormatter.link_pattern', None)
test_case.links.extend(scenario_links(scenario, issue_pattern=issue_pattern, link_pattern=link_pattern))
test_case.links.extend(scenario_links(
scenario,
issue_pattern=self.issue_pattern,
link_pattern=self.link_pattern))
test_case.labels.extend(scenario_labels(scenario))
test_case.labels.append(Label(name=LabelType.FEATURE, value=scenario.feature.name))
test_case.labels.append(Label(name=LabelType.FRAMEWORK, value='behave'))
Expand Down Expand Up @@ -191,6 +194,36 @@ def attach_data(self, body, name, attachment_type, extension):
def attach_file(self, source, name, attachment_type, extension):
self.logger.attach_file(uuid4(), source, name=name, attachment_type=attachment_type, extension=extension)

@allure_commons.hookimpl
def add_description(self, test_description):
test_result = self.logger.get_test(None)
if test_result:
test_result.description = test_description

@allure_commons.hookimpl
def add_description_html(self, test_description_html):
test_result = self.logger.get_test(None)
if test_result:
test_result.descriptionHtml = test_description_html

@allure_commons.hookimpl
def add_link(self, url, link_type, name):
test_result = self.logger.get_test(None)
if test_result:
pattern = u'{}'
if link_type == LinkType.ISSUE and self.issue_pattern:
pattern = self.issue_pattern
elif link_type == LinkType.LINK and self.link_pattern:
pattern = self.link_pattern

link_url = pattern.format(url)
new_link = Link(link_type, link_url, link_url if name is None else name)
for link in test_result.links:
if link.url == new_link.url:
return

test_result.links.append(new_link)


class Context(list):
def __init__(self, _list=list()):
Expand Down