Skip to content

Commit

Permalink
drop excluded tests by tags or test_plan.json (#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
sseliverstov authored Jun 2, 2021
1 parent a4e7f7f commit 9b0cde4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
46 changes: 45 additions & 1 deletion allure-behave/features/test_plan.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,54 @@ Feature: Test plan
"""
When I run behave with allure formatter
Then allure report has a scenario with name "Scenario with passed step"
Then allure report has a scenario with name "Ignored scenario"
And this scenario has "skipped" status
Then allure report has a scenario with name "Another scenario with passed step"
Then allure report has a scenario with name "Another ignored scenario"
And this scenario has "skipped" status

Scenario: Drop unselected test from report
Given feature definition
"""
Feature: Test plan example
Scenario: Scenario with passed step
Given passed step
Scenario: Ignored scenario
Given passed step
"""
Given feature definition
"""
Feature: Another Test plan example
Scenario: Another scenario with passed step
Given passed step
Scenario: Another ignored scenario
Given passed step
"""
Given test plan
"""
{
"version":"1.0",
"tests": [
{
"selector": "Test plan example: Scenario with passed step"
},
{
"selector": "Another Test plan example: Another scenario with passed step"
}
]
}
"""
When I run behave with allure formatter with options "-D AllureFormatter.hide_excluded=True"
Then allure report has a scenario with name "Scenario with passed step"
Then allure report has not a scenario with name "Ignored scenario"
Then allure report has a scenario with name "Another scenario with passed step"
Then allure report has not a scenario with name "Another ignored scenario"


Scenario: Select scenarios by allureid
Given feature definition
"""
Expand Down Expand Up @@ -79,7 +123,7 @@ Feature: Test plan
]
}
"""
When I run behave with allure formatter
When I run behave with allure formatter with options "-D AllureFormatter.hide_excluded=True"
Then allure report has a scenario with name "Scenario with passed step"
Then allure report has not a scenario with name "Ignored scenario"
Then allure report has a scenario with name "Another scenario with passed step"
Expand Down
9 changes: 7 additions & 2 deletions allure-behave/src/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ 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.hide_excluded = behave_config.userdata.get('AllureFormatter.hide_excluded', False)
self.logger = AllureReporter()
self.current_step_uuid = None
self.current_scenario_uuid = None
Expand Down Expand Up @@ -118,8 +119,12 @@ def stop_test(self, parent_uuid, uuid, name, context, exc_type, exc_val, exc_tb)
self.stop_scenario(context['scenario'])

def stop_scenario(self, scenario):
if scenario.status == 'skipped' \
and not self.behave_config.show_skipped or scenario.skip_reason == TEST_PLAN_SKIP_REASON:
should_run = (scenario.should_run_with_tags(self.behave_config.tags) and
scenario.should_run_with_name_select(self.behave_config))
should_drop_skipped_by_option = scenario.status == 'skipped' and not self.behave_config.show_skipped
should_drop_excluded = self.hide_excluded and (scenario.skip_reason == TEST_PLAN_SKIP_REASON or not should_run)

if should_drop_skipped_by_option or should_drop_excluded:
self.logger.drop_test(self.current_scenario_uuid)
else:
status = scenario_status(scenario)
Expand Down

0 comments on commit 9b0cde4

Please sign in to comment.