Skip to content

Commit 54b2fe2

Browse files
wangxinAndoniSanguesa
authored andcommitted
Improve anchor definition in conditional mark (sonic-net#21943)
PR sonic-net#20326 introduced anchors in the conditional mark yaml files. The anchors are defined in a dummy entry for test_pretest.py. PR sonic-net#20382 updated code to add exception for the sort checking of test_pretest.py in conditional mark yaml files. These changes made it complicated when we do need to skip something for test_pretest.py. This change fixed the problem by using a real dummy entry for defining the yaml anchors. The code of skipping test_pretest.py in sort checking in conditional mark yaml file is also removed. This change also improved a variable name in conditional mark and fixed a few typos. Signed-off-by: Xin Wang <[email protected]> Signed-off-by: Andoni Sanguesa <[email protected]>
1 parent 39ef50f commit 54b2fe2

3 files changed

Lines changed: 40 additions & 50 deletions

File tree

.hooks/pre_commit_hooks/check_conditional_mark_sort.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ def main():
1414
for line in file_contents:
1515
if re.match('^[a-zA-Z]', line):
1616
conditions.append(line.strip().rstrip(":"))
17-
if conditions[0] == 'test_pretest.py':
18-
del conditions[0] # This is at front where it should be
19-
if 'test_pretest.py' in conditions:
20-
print("===========================================================================")
21-
print("test_pretest.py should be the first item in ")
22-
print("tests/common/plugins/conditional_mark/tests_mark_conditions*.yaml")
23-
print("===========================================================================")
24-
return 1
2517
sorted_conditions = conditions[:]
2618
sorted_conditions.sort()
2719
for i in range(len(conditions)):

tests/common/plugins/conditional_mark/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ def load_conditions(session):
7878
conditions_list = list()
7979

8080
conditions_files = session.config.option.mark_conditions_files
81-
for condition in conditions_files:
82-
if '*' in condition:
83-
conditions_files.remove(condition)
84-
files = glob.glob(condition)
81+
for condition_file in conditions_files:
82+
if '*' in condition_file:
83+
conditions_files.remove(condition_file)
84+
files = glob.glob(condition_file)
8585
for file in files:
8686
if file not in conditions_files:
8787
conditions_files.append(file)
@@ -643,7 +643,7 @@ def pytest_collection(session):
643643

644644

645645
def pytest_collection_modifyitems(session, config, items):
646-
"""Hook for adding marks to test cases based on conditions defind in a centralized file.
646+
"""Hook for adding marks to test cases based on conditions defined in a centralized file.
647647
648648
Args:
649649
session (obj): Pytest session object.

tests/common/plugins/conditional_mark/tests_mark_conditions.yaml

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,41 @@
22
##### Define Anchors #####
33
#######################################
44

5-
# yaml files don't let an anchor be defined outside a yaml entry, so this block just
6-
# creates an entry for pre-test but ensure it will always run, then the other
7-
# conditions can just be used to define anchors for further use in this file
8-
9-
test_pretest.py:
10-
skip:
11-
reason: "Dummy entry to allow anchors to be defined at the top of this file"
12-
conditions_logical_operator: and
13-
conditions:
14-
- "False" # Ensure pretest always runs
15-
- &lossyTopos |
16-
topo_name in [
17-
't0-isolated-d128u128s1', 't0-isolated-v6-d128u128s1',
18-
't0-isolated-d128u128s2', 't0-isolated-v6-d128u128s2',
19-
't0-isolated-d16u16s1', 't0-isolated-v6-d16u16s1',
20-
't0-isolated-d16u16s2', 't0-isolated-v6-d16u16s2',
21-
't0-isolated-d256u256s2', 't0-isolated-v6-d256u256s2',
22-
't0-isolated-d32u32s2', 't0-isolated-v6-d32u32s2',
23-
't1-isolated-d224u8', 't1-isolated-v6-d224u8',
24-
't1-isolated-d28u1', 't1-isolated-v6-d28u1',
25-
't1-isolated-d448u15-lag', 't1-isolated-v6-d448u15-lag',
26-
't1-isolated-d448u16', 't1-isolated-v6-d448u16',
27-
't1-isolated-d56u1-lag', 't1-isolated-v6-d56u1-lag',
28-
't1-isolated-d56u2', 't1-isolated-v6-d56u2' ]
29-
- &noVxlanTopos |
30-
topo_name in [
31-
't0-isolated-d32u32s2', 't0-isolated-d256u256s2',
32-
't0-isolated-d96u32s2', 't0-isolated-v6-d32u32s2',
33-
't0-isolated-v6-d256u256s2', 't0-isolated-v6-d96u32s2',
34-
't1-isolated-d56u2', 't1-isolated-d56u1-lag',
35-
't1-isolated-d448u15-lag', 't1-isolated-d128',
36-
't1-isolated-d32', 't1-isolated-v6-d56u2',
37-
't1-isolated-v6-d56u1-lag', 't1-isolated-v6-d448u15-lag',
38-
't1-isolated-v6-d128' ]
39-
40-
#######################################
41-
##### cutsom_acl #####
5+
# This entry should not match any tests, it is just for defining anchors
6+
# yaml files don't let an anchor be defined outside a yaml entry, so this entry just
7+
# creates an entry defining anchors by &anchor_name. The anchors are like variables that can be reused
8+
# in later conditions by syntax like *anchor_name.
9+
# The name of this entry can ensure that is is sorted to the top of the file.
10+
# Because it does not match any tests, so the schema of this entry can be flexible.
11+
0000aaaa_dummy_entry:
12+
anchors:
13+
- &lossyTopos |
14+
topo_name in [
15+
't0-isolated-d128u128s1', 't0-isolated-v6-d128u128s1',
16+
't0-isolated-d128u128s2', 't0-isolated-v6-d128u128s2',
17+
't0-isolated-d16u16s1', 't0-isolated-v6-d16u16s1',
18+
't0-isolated-d16u16s2', 't0-isolated-v6-d16u16s2',
19+
't0-isolated-d256u256s2', 't0-isolated-v6-d256u256s2',
20+
't0-isolated-d32u32s2', 't0-isolated-v6-d32u32s2',
21+
't1-isolated-d224u8', 't1-isolated-v6-d224u8',
22+
't1-isolated-d28u1', 't1-isolated-v6-d28u1',
23+
't1-isolated-d448u15-lag', 't1-isolated-v6-d448u15-lag',
24+
't1-isolated-d448u16', 't1-isolated-v6-d448u16',
25+
't1-isolated-d56u1-lag', 't1-isolated-v6-d56u1-lag',
26+
't1-isolated-d56u2', 't1-isolated-v6-d56u2' ]
27+
- &noVxlanTopos |
28+
topo_name in [
29+
't0-isolated-d32u32s2', 't0-isolated-d256u256s2',
30+
't0-isolated-d96u32s2', 't0-isolated-v6-d32u32s2',
31+
't0-isolated-v6-d256u256s2', 't0-isolated-v6-d96u32s2',
32+
't1-isolated-d56u2', 't1-isolated-d56u1-lag',
33+
't1-isolated-d448u15-lag', 't1-isolated-d128',
34+
't1-isolated-d32', 't1-isolated-v6-d56u2',
35+
't1-isolated-v6-d56u1-lag', 't1-isolated-v6-d448u15-lag',
36+
't1-isolated-v6-d128' ]
37+
38+
#######################################
39+
##### custom_acl #####
4240
#######################################
4341
acl:
4442
skip:

0 commit comments

Comments
 (0)