Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance conditional mark logic with use_longest for special cases #17317

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tests/common/plugins/conditional_mark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,17 @@ def find_all_matches(nodeid, conditions, session, dynamic_update_skip_reason, ba
match = re.search(condition_entry, nodeid)
else:
match = None

elif "use_longest" in condition_items.keys():
assert isinstance(condition_items["use_longest"], bool), \
"The value of 'use_longest' in the mark conditions yaml should be bool type."
if nodeid.startswith(condition_entry) and condition_items["use_longest"] is True:
all_matches = []

match = nodeid.startswith(condition_entry)
else:
match = nodeid.startswith(condition_entry)

if match:
all_matches.append(condition)

Expand All @@ -442,6 +451,9 @@ def find_all_matches(nodeid, conditions, session, dynamic_update_skip_reason, ba
length = len(case_starting_substring)
marks = match[case_starting_substring].keys()
for mark in marks:
if mark in ["regex", "use_longest"]:
continue

condition_value = evaluate_conditions(dynamic_update_skip_reason, match[case_starting_substring][mark],
match[case_starting_substring][mark].get('conditions'), basic_facts,
match[case_starting_substring][mark].get(
Expand Down Expand Up @@ -636,7 +648,7 @@ def pytest_collection_modifyitems(session, config, items):
for match in all_matches:
# match is a dict which has only one item, so we use match.values()[0] to get its value.
for mark_name, mark_details in list(list(match.values())[0].items()):
if mark_name == "regex":
if mark_name in ["regex", "use_longest"]:
continue
conditions_logical_operator = mark_details.get('conditions_logical_operator', 'AND').upper()
add_mark = False
Expand Down
2 changes: 1 addition & 1 deletion tests/common/plugins/conditional_mark/unit_test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The unit tests cover the following scenarios:
- Test duplicated conditions
- Test contradicting conditions
- Test no matches

- Test only use the longest match

### How to run tests
To execute the unit tests, we can follow below command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,49 @@ test_conditional_mark.py::test_mark_7:
conditions:
- "topo_type in ['t0']"
- "topo_type not in ['t0']"

test_conditional_mark.py::test_mark_8:
use_longest: True
skip:
reason: "Skip test_conditional_mark.py::test_mark_8"
conditions:
- "asic_type in ['mellanox']"

test_conditional_mark.py::test_mark_8_1:
use_longest: True
skip:
reason: "Skip test_conditional_mark.py::test_mark_8_1"
conditions:
- "asic_type in ['mellanox']"

test_conditional_mark.py::test_mark_8_2:
use_longest: True
skip:
reason: "Skip test_conditional_mark.py::test_mark_8_2"
conditions:
- "asic_type in ['vs']"

test_conditional_mark.py::test_mark_9:
use_longest: True
skip:
reason: "Skip test_conditional_mark.py::test_mark_9"
conditions:
- "asic_type in ['vs']"

test_conditional_mark.py::test_mark_9_1:
use_longest: True
skip:
reason: "Skip test_conditional_mark.py::test_mark_9_1"
conditions:
- "asic_type in ['vs']"

test_conditional_mark.py::test_mark_9_2:
use_longest: True
skip:
reason: "Skip test_conditional_mark.py::test_mark_9_2"
conditions:
- "asic_type in ['mellanox']"
xfail:
reason: "Xfail test_conditional_mark.py::test_mark_9_2"
conditions:
- "asic_type in ['vs']"
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,87 @@ def test_no_matches(self):
matches = find_all_matches(nodeid, conditions, session_mock, DYNAMIC_UPDATE_SKIP_REASON, CUSTOM_BASIC_FACTS)
self.assertFalse(matches)

# Test case 11: Test only use the longest match
def test_only_use_the_longest_1(self):
conditions, session_mock = load_test_conditions()
nodeid = "test_conditional_mark.py::test_mark_8"
matches = find_all_matches(nodeid, conditions, session_mock, DYNAMIC_UPDATE_SKIP_REASON, CUSTOM_BASIC_FACTS)
self.assertFalse(matches)

def test_only_use_the_longest_2(self):
conditions, session_mock = load_test_conditions()
nodeid = "test_conditional_mark.py::test_mark_8_1"
matches = find_all_matches(nodeid, conditions, session_mock, DYNAMIC_UPDATE_SKIP_REASON, CUSTOM_BASIC_FACTS)
self.assertFalse(matches)

def test_only_use_the_longest_3(self):
conditions, session_mock = load_test_conditions()
nodeid = "test_conditional_mark.py::test_mark_8_2"

marks_found = []
matches = find_all_matches(nodeid, conditions, session_mock, DYNAMIC_UPDATE_SKIP_REASON, CUSTOM_BASIC_FACTS)

for match in matches:
for mark_name, mark_details in list(list(match.values())[0].items()):
marks_found.append(mark_name)

if mark_name == "skip":
self.assertEqual(mark_details.get("reason"), "Skip test_conditional_mark.py::test_mark_8_2")

self.assertEqual(len(marks_found), 1)
self.assertIn('skip', marks_found)

def test_only_use_the_longest_4(self):
conditions, session_mock = load_test_conditions()
nodeid = "test_conditional_mark.py::test_mark_9"

marks_found = []
matches = find_all_matches(nodeid, conditions, session_mock, DYNAMIC_UPDATE_SKIP_REASON, CUSTOM_BASIC_FACTS)

for match in matches:
for mark_name, mark_details in list(list(match.values())[0].items()):
marks_found.append(mark_name)

if mark_name == "skip":
self.assertEqual(mark_details.get("reason"), "Skip test_conditional_mark.py::test_mark_9")

self.assertEqual(len(marks_found), 1)
self.assertIn('skip', marks_found)

def test_only_use_the_longest_5(self):
conditions, session_mock = load_test_conditions()
nodeid = "test_conditional_mark.py::test_mark_9_1"

marks_found = []
matches = find_all_matches(nodeid, conditions, session_mock, DYNAMIC_UPDATE_SKIP_REASON, CUSTOM_BASIC_FACTS)

for match in matches:
for mark_name, mark_details in list(list(match.values())[0].items()):
marks_found.append(mark_name)

if mark_name == "skip":
self.assertEqual(mark_details.get("reason"), "Skip test_conditional_mark.py::test_mark_9_1")

self.assertEqual(len(marks_found), 1)
self.assertIn('skip', marks_found)

def test_only_use_the_longest_6(self):
conditions, session_mock = load_test_conditions()
nodeid = "test_conditional_mark.py::test_mark_9_2"

marks_found = []
matches = find_all_matches(nodeid, conditions, session_mock, DYNAMIC_UPDATE_SKIP_REASON, CUSTOM_BASIC_FACTS)

for match in matches:
for mark_name, mark_details in list(list(match.values())[0].items()):
marks_found.append(mark_name)

if mark_name == "xfail":
self.assertEqual(mark_details.get("reason"), "Xfail test_conditional_mark.py::test_mark_9_2")

self.assertEqual(len(marks_found), 1)
self.assertIn('xfail', marks_found)


if __name__ == "__main__":
unittest.main()
Loading