This repository has been archived by the owner on Apr 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9225 from mshriver/polarion-custscenario
[1LP][RFR] Add customer scenario marker/filter, move tier and requirement markers
- Loading branch information
Showing
13 changed files
with
410 additions
and
313 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
"""Marker definitions for tier and requirement, and meta filter plugin | ||
""" | ||
import re | ||
|
||
from cfme.fixtures.pytest_store import store | ||
|
||
|
||
TEST_PARAM_FILTER = re.compile(r"\[.*\]") | ||
|
||
|
||
# Markers | ||
def pytest_configure(config): | ||
if config.getoption('--help'): | ||
return | ||
markers_to_add = [ | ||
'tier: mark a test case with a tier', | ||
'requirement: mark a test case with a requirement', | ||
'customer_scenario: mark a test case as a customer story', | ||
] | ||
for marker in markers_to_add: | ||
config.addinivalue_line('markers', marker) | ||
|
||
|
||
# Filtering options | ||
def pytest_addoption(parser): | ||
group = parser.getgroup('cfme') | ||
group.addoption('--tier', | ||
type=int, | ||
action='append', | ||
help='only run tests of the given tier levels') | ||
group.addoption('--requirement', | ||
type=str, | ||
action='append', | ||
help='only run tests with given requirement markers') | ||
group.addoption('--customer-scenario', | ||
action='store_true', | ||
default=False, | ||
help='only run tests marked with customer_scenario') | ||
|
||
|
||
def pytest_collection_modifyitems(session, config, items): | ||
"""Provide filtering of test case collection based on the CLI options""" | ||
tiers = config.getoption('tier') | ||
requirements = config.getoption('requirement') | ||
customer = config.getoption('customer_scenario') | ||
if not tiers and not requirements and not customer: | ||
return | ||
# TODO(rpfannsc) trim after pytest #1373 is done | ||
keep, discard_tier, discard_requirement, discard_customer = [], [], [], [] | ||
|
||
for item in items: | ||
# for each filter, check if its active and that the item has the marker | ||
# Then check if the marker content matches the passed filter | ||
# Discard items without the matching value | ||
if (tiers and | ||
not getattr(item.get_marker('tier'), 'args', [False])[0] in tiers): | ||
discard_tier.append(item) | ||
continue | ||
if (requirements and | ||
not getattr(item.get_marker('requirement'), 'args', [False])[0] in requirements): | ||
discard_requirement.append(item) | ||
continue | ||
if customer and item.get_marker('customer_scenario') is None: | ||
discard_customer.append(item) | ||
continue | ||
keep.append(item) | ||
|
||
items[:] = keep | ||
# TODO(rpfannsc) add a reason after pytest #1372 is fixed | ||
discarded = discard_tier + discard_requirement + discard_customer | ||
config.hook.pytest_deselected(items=discarded) | ||
if tiers: | ||
store.uncollection_stats['tier mark'] = len(discard_tier) | ||
if requirements: | ||
store.uncollection_stats['requirement mark'] = len(discard_requirement) | ||
if customer: | ||
store.uncollection_stats['customer_scenario mark'] = len(discard_customer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.