Skip to content

Commit e24331d

Browse files
authored
behave: do not report tests with --no-skipped option (fixes #211 fixes #142 via #249)
1 parent acba368 commit e24331d

File tree

5 files changed

+75
-15
lines changed

5 files changed

+75
-15
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Feature: Behave cmd options
2+
3+
Scenario: Tags in scenario with options "--tags=tag"
4+
Given feature definition
5+
"""
6+
Feature: Tags filtering
7+
8+
@tag
9+
Scenario: Scenario with tag
10+
Given simple passed step
11+
12+
Scenario: Scenario without tag
13+
Given simple passed step
14+
"""
15+
When I run behave with allure formatter with options "--tags=tag"
16+
Then allure report has a scenario with name "Scenario with tag"
17+
And this scenario has "passed" status
18+
19+
Then allure report has a scenario with name "Scenario without tag"
20+
And this scenario has "skipped" status
21+
22+
Scenario: Tags in scenario with options "--tags=tag --no-skipped"
23+
Given feature definition
24+
"""
25+
Feature: Tags filtering
26+
27+
@tag
28+
Scenario: Scenario with tag
29+
Given simple passed step
30+
31+
Scenario: Scenario without tag
32+
Given simple passed step
33+
"""
34+
When I run behave with allure formatter with options "--tags=tag --no-skipped"
35+
Then allure report has a scenario with name "Scenario with tag"
36+
And this scenario has "passed" status
37+
38+
Then allure report has not a scenario with name "Scenario without tag"

allure-behave/features/steps/report_steps.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ def step_scenario(context, scenario):
3131
assert_that(context.allure_report, matcher())
3232

3333

34+
@then(u'allure report has not a scenario with name "{scenario}"')
35+
def step_scenario(context, scenario):
36+
matcher = partial(match, not_, has_test_case, scenario)
37+
context.scenario = matcher
38+
assert_that(context.allure_report, matcher())
39+
40+
3441
@then(u'scenario has before fixture "{fixture}"')
3542
@then(u'this scenario has before fixture "{fixture}"')
3643
def step_before_fixture(context, fixture):

allure-behave/src/formatter.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import print_function
2+
13
from behave.model import ScenarioOutline
24
from behave.formatter.base import Formatter
35
import allure_commons
@@ -9,7 +11,12 @@ class AllureFormatter(Formatter):
911
def __init__(self, stream_opener, config):
1012
super(AllureFormatter, self).__init__(stream_opener, config)
1113

12-
self.listener = AllureListener()
14+
self.config = config
15+
16+
with open("debug-runner", "a") as debugfile:
17+
print(config.show_skipped, file=debugfile)
18+
19+
self.listener = AllureListener(config)
1320
file_logger = AllureFileLogger(self.stream_opener.name)
1421

1522
allure_commons.plugin_manager.register(self.listener)

allure-behave/src/listener.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030

3131
class AllureListener(object):
32-
def __init__(self):
32+
def __init__(self, behave_config):
33+
self.behave_config = behave_config
3334
self.logger = AllureReporter()
3435
self.current_step_uuid = None
3536
self.execution_context = Context()
@@ -102,19 +103,23 @@ def start_test(self, parent_uuid, uuid, name, parameters, context):
102103
@allure_commons.hookimpl
103104
def stop_test(self, parent_uuid, uuid, name, context, exc_type, exc_val, exc_tb):
104105
scenario = context['scenario']
105-
self.flush_steps()
106-
status = scenario_status(scenario)
107-
status_details = scenario_status_details(scenario)
108-
test_result = self.logger.get_test(uuid)
109-
test_result.stop = now()
110-
test_result.status = status
111-
test_result.statusDetails = status_details
112-
self.logger.close_test(uuid)
113-
self.current_step_uuid = None
114-
115-
for group in self.fixture_context.exit():
116-
group.children.append(uuid)
117-
self.logger.stop_group(group.uuid)
106+
if scenario.status == 'skipped' and not self.behave_config.show_skipped:
107+
self.logger.drop_test(uuid)
108+
else:
109+
status = scenario_status(scenario)
110+
status_details = scenario_status_details(scenario)
111+
112+
self.flush_steps()
113+
test_result = self.logger.get_test(uuid)
114+
test_result.stop = now()
115+
test_result.status = status
116+
test_result.statusDetails = status_details
117+
self.logger.close_test(uuid)
118+
self.current_step_uuid = None
119+
120+
for group in self.fixture_context.exit():
121+
group.children.append(uuid)
122+
self.logger.stop_group(group.uuid)
118123

119124
self.execution_context.exit()
120125
self.execution_context.append(uuid)

allure-python-commons/src/reporter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ def close_test(self, uuid):
7575
test_case = self._items.pop(uuid)
7676
plugin_manager.hook.report_result(result=test_case)
7777

78+
def drop_test(self, uuid):
79+
self._items.pop(uuid)
80+
7881
def start_step(self, parent_uuid, uuid, step):
7982
parent_uuid = parent_uuid if parent_uuid else self._last_executable()
8083
if parent_uuid is None:

0 commit comments

Comments
 (0)