Skip to content

Commit 2179ac3

Browse files
authored
Merge branch 'master' into allure_step_in_thread
2 parents 4b5f545 + 9b0cde4 commit 2179ac3

File tree

22 files changed

+323
-98
lines changed

22 files changed

+323
-98
lines changed

allure-behave/features/description.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,24 @@ Feature: Description
1313
"""
1414
When I run behave with allure formatter
1515
Then allure report has a scenario with name "Scenario with description"
16+
17+
Scenario: Dynamic description
18+
Given feature definition
19+
"""
20+
Feature: Step status
21+
22+
Scenario: Scenario with passed step
23+
Given simple passed step
24+
"""
25+
And hooks implementation
26+
"""
27+
import allure
28+
import allure_commons
29+
30+
@allure_commons.fixture
31+
def before_scenario(context, scenario):
32+
allure.dynamic.description("Test description")
33+
"""
34+
When I run behave with allure formatter
35+
Then allure report has a scenario with name "Scenario with passed step"
36+
And scenario has description "Test description"

allure-behave/features/link.feature

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Feature: Link
22

3-
Scenario: Scenario issue link
3+
Scenario: Scenario issue link
44
Given feature definition
55
"""
66
Feature: Step status
@@ -26,7 +26,6 @@ Feature: Link
2626
Then allure report has a scenario with name "Scenario with passed step"
2727
And scenario has "http://qameta.io" link
2828

29-
3029
Scenario: Feature and scenario user link
3130
Given feature definition
3231
"""
@@ -41,3 +40,26 @@ Feature: Link
4140
Then allure report has a scenario with name "Scenario with passed step"
4241
And scenario has "http://qameta.io" link
4342
And scenario has "http://example.com" link with type "issue"
43+
44+
Scenario: Dynamic link
45+
Given feature definition
46+
"""
47+
Feature: Step status
48+
49+
Scenario: Scenario with passed step
50+
Given simple passed step
51+
"""
52+
And hooks implementation
53+
"""
54+
import allure
55+
import allure_commons
56+
57+
@allure_commons.fixture
58+
def before_scenario(context, scenario):
59+
allure.dynamic.link("http://qameta.io")
60+
allure.dynamic.issue("http://example.com")
61+
"""
62+
When I run behave with allure formatter
63+
Then allure report has a scenario with name "Scenario with passed step"
64+
And scenario has "http://qameta.io" link
65+
And scenario has "http://example.com" link with type "issue"

allure-behave/features/steps/report_steps.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from functools import partial
2-
from hamcrest import assert_that
2+
from hamcrest import assert_that, contains_string
33
from hamcrest import not_
44
from allure_commons_test.report import has_test_case
55
from allure_commons_test.result import with_status
@@ -9,6 +9,7 @@
99
from allure_commons_test.result import has_status_details
1010
from allure_commons_test.result import with_message_contains
1111
from allure_commons_test.result import has_link
12+
from allure_commons_test.result import has_description
1213
from allure_commons_test.container import has_container
1314
from allure_commons_test.container import has_before, has_after
1415
from allure_commons_test.label import has_severity
@@ -149,3 +150,10 @@ def step_attachment(context, item):
149150
context_matcher = getattr(context, item)
150151
matcher = partial(context_matcher, has_attachment)
151152
assert_that(context.allure_report, matcher())
153+
154+
155+
@then(u'scenario has description "{description}"')
156+
def step_description(context, description):
157+
context_matcher = context.scenario
158+
matcher = partial(context_matcher, has_description, contains_string(description))
159+
assert_that(context.allure_report, matcher())

allure-behave/features/test_plan.feature

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,54 @@ Feature: Test plan
3636
"""
3737
When I run behave with allure formatter
3838
Then allure report has a scenario with name "Scenario with passed step"
39+
Then allure report has a scenario with name "Ignored scenario"
40+
And this scenario has "skipped" status
41+
Then allure report has a scenario with name "Another scenario with passed step"
42+
Then allure report has a scenario with name "Another ignored scenario"
43+
And this scenario has "skipped" status
44+
45+
Scenario: Drop unselected test from report
46+
Given feature definition
47+
"""
48+
Feature: Test plan example
49+
50+
Scenario: Scenario with passed step
51+
Given passed step
52+
53+
Scenario: Ignored scenario
54+
Given passed step
55+
"""
56+
Given feature definition
57+
"""
58+
Feature: Another Test plan example
59+
60+
Scenario: Another scenario with passed step
61+
Given passed step
62+
63+
Scenario: Another ignored scenario
64+
Given passed step
65+
"""
66+
Given test plan
67+
"""
68+
{
69+
"version":"1.0",
70+
"tests": [
71+
{
72+
"selector": "Test plan example: Scenario with passed step"
73+
},
74+
{
75+
"selector": "Another Test plan example: Another scenario with passed step"
76+
}
77+
]
78+
}
79+
"""
80+
When I run behave with allure formatter with options "-D AllureFormatter.hide_excluded=True"
81+
Then allure report has a scenario with name "Scenario with passed step"
3982
Then allure report has not a scenario with name "Ignored scenario"
4083
Then allure report has a scenario with name "Another scenario with passed step"
4184
Then allure report has not a scenario with name "Another ignored scenario"
4285

86+
4387
Scenario: Select scenarios by allureid
4488
Given feature definition
4589
"""
@@ -79,7 +123,7 @@ Feature: Test plan
79123
]
80124
}
81125
"""
82-
When I run behave with allure formatter
126+
When I run behave with allure formatter with options "-D AllureFormatter.hide_excluded=True"
83127
Then allure report has a scenario with name "Scenario with passed step"
84128
Then allure report has not a scenario with name "Ignored scenario"
85129
Then allure report has a scenario with name "Another scenario with passed step"

allure-behave/src/listener.py

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
from allure_commons.utils import uuid4
77
from allure_commons.utils import now
88
from allure_commons.utils import platform_label
9-
from allure_commons.types import LabelType, AttachmentType
9+
from allure_commons.types import LabelType, AttachmentType, LinkType
1010
from allure_commons.model2 import TestResult
1111
from allure_commons.model2 import TestStepResult
1212
from allure_commons.model2 import TestBeforeResult, TestAfterResult
1313
from allure_commons.model2 import TestResultContainer
14-
from allure_commons.model2 import Parameter, Label
14+
from allure_commons.model2 import Parameter, Label, Link
1515
from allure_behave.utils import scenario_parameters
1616
from allure_behave.utils import scenario_name
1717
from allure_behave.utils import scenario_history_id
@@ -33,6 +33,9 @@
3333
class AllureListener(object):
3434
def __init__(self, behave_config):
3535
self.behave_config = behave_config
36+
self.issue_pattern = behave_config.userdata.get('AllureFormatter.issue_pattern', None)
37+
self.link_pattern = behave_config.userdata.get('AllureFormatter.link_pattern', None)
38+
self.hide_excluded = behave_config.userdata.get('AllureFormatter.hide_excluded', False)
3639
self.logger = AllureReporter()
3740
self.current_step_uuid = None
3841
self.current_scenario_uuid = None
@@ -100,9 +103,10 @@ def start_scenario(self, scenario):
100103
test_case.description = '\n'.join(scenario.description)
101104
test_case.parameters = scenario_parameters(scenario)
102105

103-
issue_pattern = self.behave_config.userdata.get('AllureFormatter.issue_pattern', None)
104-
link_pattern = self.behave_config.userdata.get('AllureFormatter.link_pattern', None)
105-
test_case.links.extend(scenario_links(scenario, issue_pattern=issue_pattern, link_pattern=link_pattern))
106+
test_case.links.extend(scenario_links(
107+
scenario,
108+
issue_pattern=self.issue_pattern,
109+
link_pattern=self.link_pattern))
106110
test_case.labels.extend(scenario_labels(scenario))
107111
test_case.labels.append(Label(name=LabelType.FEATURE, value=scenario.feature.name))
108112
test_case.labels.append(Label(name=LabelType.FRAMEWORK, value='behave'))
@@ -115,8 +119,12 @@ def stop_test(self, parent_uuid, uuid, name, context, exc_type, exc_val, exc_tb)
115119
self.stop_scenario(context['scenario'])
116120

117121
def stop_scenario(self, scenario):
118-
if scenario.status == 'skipped' \
119-
and not self.behave_config.show_skipped or scenario.skip_reason == TEST_PLAN_SKIP_REASON:
122+
should_run = (scenario.should_run_with_tags(self.behave_config.tags) and
123+
scenario.should_run_with_name_select(self.behave_config))
124+
should_drop_skipped_by_option = scenario.status == 'skipped' and not self.behave_config.show_skipped
125+
should_drop_excluded = self.hide_excluded and (scenario.skip_reason == TEST_PLAN_SKIP_REASON or not should_run)
126+
127+
if should_drop_skipped_by_option or should_drop_excluded:
120128
self.logger.drop_test(self.current_scenario_uuid)
121129
else:
122130
status = scenario_status(scenario)
@@ -191,6 +199,36 @@ def attach_data(self, body, name, attachment_type, extension):
191199
def attach_file(self, source, name, attachment_type, extension):
192200
self.logger.attach_file(uuid4(), source, name=name, attachment_type=attachment_type, extension=extension)
193201

202+
@allure_commons.hookimpl
203+
def add_description(self, test_description):
204+
test_result = self.logger.get_test(None)
205+
if test_result:
206+
test_result.description = test_description
207+
208+
@allure_commons.hookimpl
209+
def add_description_html(self, test_description_html):
210+
test_result = self.logger.get_test(None)
211+
if test_result:
212+
test_result.descriptionHtml = test_description_html
213+
214+
@allure_commons.hookimpl
215+
def add_link(self, url, link_type, name):
216+
test_result = self.logger.get_test(None)
217+
if test_result:
218+
pattern = u'{}'
219+
if link_type == LinkType.ISSUE and self.issue_pattern:
220+
pattern = self.issue_pattern
221+
elif link_type == LinkType.LINK and self.link_pattern:
222+
pattern = self.link_pattern
223+
224+
link_url = pattern.format(url)
225+
new_link = Link(link_type, link_url, link_url if name is None else name)
226+
for link in test_result.links:
227+
if link.url == new_link.url:
228+
return
229+
230+
test_result.links.append(new_link)
231+
194232

195233
class Context(list):
196234
def __init__(self, _list=list()):

allure-pytest/src/listener.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def pytest_runtest_call(self, item):
100100
uuid = self._cache.get(item.nodeid)
101101
test_result = self.allure_logger.get_test(uuid)
102102
if test_result:
103+
self.allure_logger.drop_test(uuid)
104+
self.allure_logger.schedule_test(uuid, test_result)
103105
test_result.start = now()
104106
yield
105107
if test_result:
@@ -266,23 +268,23 @@ def __init__(self):
266268
self._items = dict()
267269

268270
def get(self, _id):
269-
return self._items.get(str(_id))
271+
return self._items.get(id(_id))
270272

271273
def push(self, _id):
272-
return self._items.setdefault(str(_id), uuid4())
274+
return self._items.setdefault(id(_id), uuid4())
273275

274276
def pop(self, _id):
275-
return self._items.pop(str(_id), None)
277+
return self._items.pop(id(_id), None)
276278

277279

278280
def _test_fixtures(item):
279281
fixturemanager = item.session._fixturemanager
280282
fixturedefs = []
281283

282-
if hasattr(item._request, "fixturenames"):
284+
if hasattr(item, "_request") and hasattr(item._request, "fixturenames"):
283285
for name in item._request.fixturenames:
284-
fixturedef = fixturemanager.getfixturedefs(name, item.nodeid)
285-
if fixturedef:
286-
fixturedefs.append(fixturedef[-1])
286+
fixturedefs_pytest = fixturemanager.getfixturedefs(name, item.nodeid)
287+
if fixturedefs_pytest:
288+
fixturedefs.extend(fixturedefs_pytest)
287289

288290
return fixturedefs

allure-pytest/src/plugin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ def a_label_type(string):
8383
help="""Comma-separated list of story names.
8484
Run tests that have at least one of the specified story labels.""")
8585

86+
parser.getgroup("general").addoption('--allure-ids',
87+
action="store",
88+
dest="allure_ids",
89+
metavar="IDS_SET",
90+
default={},
91+
type=label_type(LabelType.ID),
92+
help="""Comma-separated list of IDs.
93+
Run tests that have at least one of the specified id labels.""")
94+
8695
def link_pattern(string):
8796
pattern = string.split(':', 1)
8897
if not pattern[0]:
@@ -145,6 +154,7 @@ def select_by_labels(items, config):
145154
arg_labels = set().union(config.option.allure_epics,
146155
config.option.allure_features,
147156
config.option.allure_stories,
157+
config.option.allure_ids,
148158
config.option.allure_severities)
149159
return filter(lambda item: arg_labels & set(allure_labels(item)) if arg_labels else True, items)
150160

allure-pytest/test/acceptance/fixture/fixture_test.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import allure
33
from hamcrest import assert_that, not_
44
from allure_commons_test.report import has_test_case
5-
from allure_commons_test.container import has_container
6-
from allure_commons_test.container import has_before
5+
from allure_commons_test.container import has_container, has_before, has_after
6+
from allure_commons_test.result import has_step
77
from itertools import combinations_with_replacement
88

99
fixture_scopes = ["session", "module", "class", "function"]
@@ -217,3 +217,58 @@ def test_with_titled_conftest_fixtures(first_fixture, second_fixture):
217217
)
218218
)
219219
)
220+
221+
222+
def test_fixture_override(allured_testdir):
223+
allured_testdir.testdir.makeconftest("""
224+
import pytest
225+
import allure
226+
227+
@pytest.fixture
228+
def my_fixture():
229+
with allure.step('Step in before in original fixture'):
230+
pass
231+
yield
232+
with allure.step('Step in after in original fixture'):
233+
pass
234+
235+
""")
236+
237+
allured_testdir.testdir.makepyfile("""
238+
import pytest
239+
import allure
240+
241+
@pytest.fixture
242+
def my_fixture(my_fixture):
243+
with allure.step('Step in before in redefined fixture'):
244+
pass
245+
yield
246+
with allure.step('Step in after in redefined fixture'):
247+
pass
248+
249+
def test_with_redefined_fixture(my_fixture):
250+
pass
251+
""")
252+
253+
allured_testdir.run_with_allure()
254+
255+
assert_that(allured_testdir.allure_report,
256+
has_test_case("test_with_redefined_fixture",
257+
has_container(allured_testdir.allure_report,
258+
has_before("my_fixture",
259+
has_step("Step in before in original fixture")
260+
),
261+
has_after("my_fixture::0",
262+
has_step("Step in after in original fixture")
263+
)
264+
),
265+
has_container(allured_testdir.allure_report,
266+
has_before("my_fixture",
267+
has_step("Step in before in redefined fixture")
268+
),
269+
has_after("my_fixture::0",
270+
has_step("Step in after in redefined fixture")
271+
)
272+
),
273+
)
274+
)

0 commit comments

Comments
 (0)