Skip to content

Commit

Permalink
Address jira issue handler pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jameerpathan111 committed Apr 17, 2024
1 parent 825e214 commit ece7884
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
8 changes: 4 additions & 4 deletions pytest_plugins/metadata_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def parse_comma_separated_list(option_value):
return True
if option_value.lower() == 'false':
return False
return option_value.split(',')
return [item.strip() for item in option_value.split(',')]
return None


Expand Down Expand Up @@ -234,7 +234,7 @@ def pytest_collection_modifyitems(items, config):
item.user_properties.append(("SnapVersion", snap_version))

# exit early if no filters were passed
if importance or component or team or verifies_issues or blocked_by:
if importance or component or team:
# Filter test collection based on CLI options for filtering
# filters should be applied together
# such that --component Repository --importance Critical --team rocket
Expand Down Expand Up @@ -267,6 +267,7 @@ def pytest_collection_modifyitems(items, config):
deselected.append(item)
continue

if verifies_issues or blocked_by:
# Filter tests based on --verifies-issues and --blocked-by pytest options
# and Verifies and BlockedBy testimony tokens.
verifies_marker = item.get_closest_marker('verifies_issues', False)
Expand All @@ -275,8 +276,7 @@ def pytest_collection_modifyitems(items, config):
continue
if not handle_blocked_by(item, blocked_by_marker, blocked_by):
continue

selected.append(item)
selected.append(item)

# selected will be empty if no filter option was passed, defaulting to full items list
items[:] = selected if deselected else items
Expand Down
8 changes: 4 additions & 4 deletions robottelo/utils/issue_handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def add_workaround(data, matches, usage, validation=(lambda *a, **k: True), **kw
def should_deselect(issue, data=None):
"""Check if test should be deselected based on marked issue."""
# Handlers can be extended to support different issue trackers.
res = re.split(':|-', issue)
handlers = {'BZ': bugzilla.should_deselect_bz, 'SAT': jira.should_deselect_jira}
supported_handlers = tuple(f"{handler}" for handler in handlers)
if str(res[0]).startswith(supported_handlers):
if str(issue).startswith(supported_handlers):
res = re.split(':|-', issue)
handler_code = res[0]
return handlers[handler_code.strip()](issue.strip(), data)
return None
Expand All @@ -38,9 +38,9 @@ def is_open(issue, data=None):
issue {str} -- A string containing handler + number e.g: BZ:123465
data {dict} -- Issue data indexed by <handler>:<number> or None
"""
res = re.split(':|-', issue)
# Handlers can be extended to support different issue trackers.
if str(res[0]).startswith(SUPPORTED_HANDLERS):
if str(issue).startswith(SUPPORTED_HANDLERS):
res = re.split(':|-', issue)
handler_code = res[0]
else: # EAFP
raise AttributeError(
Expand Down
14 changes: 10 additions & 4 deletions tests/robottelo/test_issue_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,16 @@ def test_bz_should_not_deselect(self):
@pytest.mark.parametrize('issue', ["BZ123456", "XX:123456", "KK:89456", "123456", 999999])
def test_invalid_handler(self, issue):
"""Assert is_open w/ invalid handlers raise AttributeError"""
issue_deselect = should_deselect(issue)
with pytest.raises(AttributeError):
is_open(issue)
assert issue_deselect is None
if issue == 'BZ123456':
with pytest.raises(KeyError):
should_deselect(issue)
with pytest.raises(KeyError):
is_open(issue)
else:
issue_deselect = should_deselect(issue)
with pytest.raises(AttributeError):
is_open(issue)
assert issue_deselect is None

def test_bz_cache(self, request):
"""Assert basic behavior of the --bz-cache pytest option"""
Expand Down

0 comments on commit ece7884

Please sign in to comment.