Skip to content

Commit 9b0cde4

Browse files
authored
drop excluded tests by tags or test_plan.json (#593)
1 parent a4e7f7f commit 9b0cde4

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self, behave_config):
3535
self.behave_config = behave_config
3636
self.issue_pattern = behave_config.userdata.get('AllureFormatter.issue_pattern', None)
3737
self.link_pattern = behave_config.userdata.get('AllureFormatter.link_pattern', None)
38+
self.hide_excluded = behave_config.userdata.get('AllureFormatter.hide_excluded', False)
3839
self.logger = AllureReporter()
3940
self.current_step_uuid = None
4041
self.current_scenario_uuid = None
@@ -118,8 +119,12 @@ def stop_test(self, parent_uuid, uuid, name, context, exc_type, exc_val, exc_tb)
118119
self.stop_scenario(context['scenario'])
119120

120121
def stop_scenario(self, scenario):
121-
if scenario.status == 'skipped' \
122-
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:
123128
self.logger.drop_test(self.current_scenario_uuid)
124129
else:
125130
status = scenario_status(scenario)

0 commit comments

Comments
 (0)