@@ -534,8 +534,12 @@ def _run_a_test(
534534 job : str ,
535535 job_test_name : str ,
536536 job_definition : DefaultMunch ,
537+ test_group : str = "" ,
538+ test_group_ordinal : int = 0 ,
537539) -> Tuple [Optional [Compose ], TestResult ]:
538- """Runs a singe test."""
540+ """Runs a singe test printing a test group and non-zero optional ordinal,
541+ which is used for group test runs. If a test group is provided a valid ordinal
542+ (1..N) must also be used."""
539543
540544 _print_test_banner (collection , job , job_test_name )
541545
@@ -567,6 +571,11 @@ def _run_a_test(
567571 else :
568572 print ("> run-level=Undefined" )
569573
574+ # Was a test group ordinal provided?
575+ if test_group :
576+ assert test_group_ordinal > 0
577+ print (f"> test-group={ test_group } ordinal={ test_group_ordinal } " )
578+
570579 # Render the command for this test.
571580
572581 # First extract any variables and values from 'options' (if there are any).
@@ -898,14 +907,14 @@ def _run_grouped_tests(
898907
899908 # We have a run-group structure (e.g. a name and optional compose file)
900909 # and a list of jobs (job definitions), each with at least one test in
901- # the group.
902- # We need to collect: -
910+ # the group. We collect the following into a 'grouped_tests' list: -
903911 # 0 - the name of the run-group,
904912 # 1 - the test ordinal
905913 # 2 - the job collection
906914 # 3 - the job name
907915 # 4 - the job test name
908916 # 5 - the job definition
917+ #
909918 # We'll sort after we've collected every test for this group.
910919 #
911920 # The job is a DefaultMunch and contains everything for that
@@ -919,10 +928,28 @@ def _run_grouped_tests(
919928 for run_group in job [2 ].tests [job_test_name ]["run-groups" ]:
920929 if run_group .name == run_group_name :
921930 # OK - we have a test for this group.
922- # Its ordinal must be unique!
931+ # Assume we've not seen his before...
932+ new_test : bool = True
923933 for existing_group_test in grouped_tests :
924- if run_group .ordinal == existing_group_test [1 ]:
925- # Oops - return a failure!
934+ # Have we seen this before?
935+ # If not the ordinal cannot exist in a different
936+ # collection or job.
937+ if (
938+ existing_group_test [2 ] == job [0 ]
939+ and existing_group_test [3 ] == job [1 ]
940+ and existing_group_test [4 ] == job_test_name
941+ ):
942+
943+ new_test = False
944+ break
945+
946+ if run_group .ordinal == existing_group_test [1 ] and (
947+ existing_group_test [2 ] != job [0 ]
948+ or existing_group_test [3 ] != job [1 ]
949+ ):
950+
951+ # Oops - ordinal used elsewhere in this group.
952+ # Return a failure!
926953 print ("! FAILURE" )
927954 print (
928955 f"! Test '{ job_test_name } ' ordinal"
@@ -936,17 +963,19 @@ def _run_grouped_tests(
936963 tests_ignored ,
937964 tests_failed ,
938965 )
939- # New test in the group with a unique ordinal.
940- grouped_tests .append (
941- (
942- group_struct ,
943- run_group .ordinal ,
944- job [0 ], # Collection
945- job [1 ], # Job (name)
946- job_test_name ,
947- job [2 ], # Job definition
966+
967+ if new_test :
968+ # New test in the group with a unique ordinal.
969+ grouped_tests .append (
970+ (
971+ group_struct ,
972+ run_group .ordinal ,
973+ job [0 ], # Collection
974+ job [1 ], # Job (name)
975+ job_test_name ,
976+ job [2 ], # Job definition
977+ )
948978 )
949- )
950979
951980 # We now have a set of grouped tests for a given test group in a file.
952981 # Sort them according to 'ordinal' (the first entry of the tuple)
@@ -986,10 +1015,12 @@ def _run_grouped_tests(
9861015 compose , test_result = _run_a_test (
9871016 args ,
9881017 jd_filename ,
989- grouped_test [2 ],
990- grouped_test [3 ],
991- grouped_test [4 ],
992- grouped_test [5 ],
1018+ grouped_test [2 ], # Collection
1019+ grouped_test [3 ], # Job name
1020+ grouped_test [4 ], # Test name
1021+ grouped_test [5 ], # The job definition
1022+ run_group_name ,
1023+ grouped_test [1 ], # Ordinal
9931024 )
9941025
9951026 # Always try and teardown the test compose
0 commit comments