Skip to content

Commit 2b3cded

Browse files
authored
attach in steps and fixtures (fixes allure-framework#117 via allure-framework#129)
1 parent 1819b98 commit 2b3cded

File tree

6 files changed

+59
-13
lines changed

6 files changed

+59
-13
lines changed

allure-behave/features/hook.feature

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Feature: Hook
22

3-
Scenario Outline: Hook
3+
Scenario Outline: Hook 'scenario'
44
Given feature definition
55
"""
66
Feature: Hook
@@ -32,7 +32,7 @@ Feature: Hook
3232
| after | scenario |
3333

3434

35-
Scenario Outline: Hook
35+
Scenario Outline: Hook 'tag'
3636
Given feature definition
3737
"""
3838
Feature: Hook
@@ -66,7 +66,7 @@ Feature: Hook
6666
| after | tag |
6767

6868

69-
Scenario Outline: Hook
69+
Scenario Outline: Hook 'tag'
7070
Given feature definition
7171
"""
7272
@tag_for_hook
@@ -100,7 +100,7 @@ Feature: Hook
100100
| after | tag |
101101

102102

103-
Scenario Outline: Hook
103+
Scenario Outline: Hook 'feature'
104104
Given feature definition
105105
"""
106106
Feature: Hook
@@ -132,7 +132,7 @@ Feature: Hook
132132
| after | feature |
133133

134134

135-
Scenario Outline: Hook
135+
Scenario Outline: Hook 'all'
136136
Given feature definition
137137
"""
138138
Feature: Hook
@@ -162,3 +162,26 @@ Feature: Hook
162162
| when | where |
163163
| before | all |
164164
| after | all |
165+
166+
167+
Scenario: Hook attachment
168+
Given feature definition
169+
"""
170+
Feature: Hook
171+
Scenario: Scenario with "before_feature" hook and attachment
172+
Given simple passed step
173+
"""
174+
And hooks implementation
175+
"""
176+
import allure
177+
import allure_commons
178+
179+
180+
@allure_commons.fixture
181+
def before_feature(context, feature):
182+
allure.attach('Hi there!', name='user attachment', attachment_type=allure.attachment_type.TEXT)
183+
"""
184+
When I run behave with allure formatter
185+
Then allure report has a scenario with name "Scenario with "before_feature" hook and attachment"
186+
And this scenario has before fixture "before_feature"
187+
And this before has attachment
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Feature: Step Data
1+
Feature: Step
22

33
Scenario: Step text parameter
44
Given feature definition
@@ -16,6 +16,7 @@ Feature: Step Data
1616
Then allure report has a scenario with name "Scenario with step contains text data"
1717
And scenario contains step "Given simple passed step with text data"
1818
And this step has attachment
19+
And this step has "passed" status
1920

2021

2122
Scenario: Step table parameter
@@ -35,3 +36,19 @@ Feature: Step Data
3536
Then allure report has a scenario with name "Scenario with step contains table data"
3637
And scenario contains step "Given simple passed step with table data"
3738
And this step has attachment
39+
And this step has "passed" status
40+
41+
42+
Scenario: Step attachment
43+
Given feature definition
44+
"""
45+
Feature: Step Data
46+
47+
Scenario: Scenario with step that attached data
48+
Given passed step with attachment
49+
"""
50+
When I run behave with allure formatter
51+
Then allure report has a scenario with name "Scenario with step that attached data"
52+
And scenario contains step "Given passed step with attachment"
53+
And this step has attachment
54+
And this step has "passed" status

allure-behave/features/steps/behave_steps.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from behave.formatter.base import StreamOpener
99
import threading
1010

11-
A = None
12-
1311

1412
@given(u'feature definition')
1513
@given(u'feature definition {lang}')

allure-behave/features/steps/dummy_steps.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import allure
12
from behave import given
23

34

@@ -6,6 +7,8 @@
67
@given(u'passed step {where}')
78
@given(u'{what} passed step {where}')
89
def step_impl(*args, **kwargs):
10+
if 'with attachment' in kwargs.values():
11+
allure.attach('Hi there!', name='user attachment', attachment_type=allure.attachment_type.TEXT)
912
pass
1013

1114

allure-behave/src/listener.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,26 @@ def __del__(self):
4242

4343
@allure_commons.hookimpl
4444
def start_fixture(self, parent_uuid, uuid, name, parameters):
45+
parameters = [Parameter(name=param_name, value=param_value) for param_name, param_value in parameters]
46+
4547
if name in FIXTURES and not self.fixture_context:
46-
print ("group")
4748
group = TestResultContainer(uuid=uuid4())
4849
self.logger.start_group(group.uuid, group)
4950
self.fixture_context.append(group)
5051

5152
if name in BEFORE_FIXTURES:
5253
fixture = TestBeforeResult(name=name, start=now(), parameters=parameters)
5354
for group in self.fixture_context:
54-
print ("start ", name, uuid)
5555
self.logger.start_before_fixture(group.uuid, uuid, fixture)
5656

5757
elif name in AFTER_FIXTURES:
5858
fixture = TestAfterResult(name=name, start=now(), parameters=parameters)
5959
for group in self.fixture_context:
60-
print ("start ", name, uuid)
6160
self.logger.start_after_fixture(group.uuid, uuid, fixture)
6261

6362
@allure_commons.hookimpl
6463
def stop_fixture(self, parent_uuid, uuid, name, exc_type, exc_val, exc_tb):
6564
if name in FIXTURES:
66-
print ("stop ", name, uuid)
67-
6865
status = fixture_status(exc_val, exc_tb)
6966
status_details = fixture_status_details(exc_val, exc_tb)
7067
self.logger.stop_before_fixture(uuid=uuid, stop=now(), status=status, statusDetails=status_details)
@@ -156,6 +153,14 @@ def flush_steps(self):
156153
self.start_step(step)
157154
self.stop_step(step)
158155

156+
@allure_commons.hookimpl
157+
def attach_data(self, body, name, attachment_type, extension):
158+
self.logger.attach_data(uuid4(), body, name=name, attachment_type=attachment_type, extension=extension)
159+
160+
@allure_commons.hookimpl
161+
def attach_file(self, source, name, attachment_type, extension):
162+
self.logger.attach_file(uuid4(), source, name=name, attachment_type=attachment_type, extension=extension)
163+
159164

160165
class Context(list):
161166
def __init__(self, _list=list()):

0 commit comments

Comments
 (0)