@@ -241,7 +241,7 @@ def _load(
241241
242242 # Iterate through the named files.
243243 # 'job_definitions' are all those jobs that have at least one test that is not
244- # part of a 'run-group'. 'grouped_job_definitions' arr all the definitions that
244+ # part of a 'run-group'. 'grouped_job_definitions' are all the definitions that
245245 # are part of a 'run-group', indexed by group name.
246246 # the 'grouped_job_definitions' structure is:
247247 #
@@ -536,6 +536,7 @@ def _run_a_test(
536536 job_definition : DefaultMunch ,
537537 test_group : str = "" ,
538538 test_group_ordinal : int = 0 ,
539+ test_group_environment : Optional [Dict [str , Any ]] = None ,
539540) -> Tuple [Optional [Compose ], TestResult ]:
540541 """Runs a singe test printing a test group and non-zero optional ordinal,
541542 which is used for group test runs. If a test group is provided a valid ordinal
@@ -655,13 +656,19 @@ def _run_a_test(
655656 # Extract them here to pass to the test.
656657 if "environment" in job_definition .tests [job_test_name ]:
657658 for env_name in job_definition .tests [job_test_name ].environment :
658- env_value : Optional [str ] = os .environ .get (env_name , None )
659- if env_value is None :
660- print ("! FAILURE" )
661- print ("! Test environment variable is not defined" )
662- print (f"! variable={ env_name } " )
663- # Record but do no further processing
664- return None , TestResult .FAILED
659+ if test_group_environment and env_name in test_group_environment :
660+ # The environment variable is provided by the test group,
661+ # we don't need to go to the OS, we'll use what's provided.
662+ env_value : Optional [str ] = str (test_group_environment [env_name ])
663+ else :
664+ env_value = os .environ .get (env_name , None )
665+ if env_value is None :
666+ print ("! FAILURE" )
667+ print ("! Test environment variable is not defined" )
668+ print (f"! variable={ env_name } " )
669+ # Record but do no further processing
670+ return None , TestResult .FAILED
671+ assert env_value
665672 test_environment [env_name ] = env_value
666673
667674 # Get the raw (encoded) command from the job definition...
@@ -884,9 +891,9 @@ def _run_grouped_tests(
884891 # the job-definition path and filename. For each entry there's a list
885892 # that contains the 'group-name', the 'test-group' and a list of 'jobs'.
886893 # 'test-group' is the test group from the original definition
887- # (i.e. having a name and optional compose-file) and 'jobs' is a list of job
888- # definitions (DefaultMunch stuff) for jobs that have at least one test
889- # that runs in that group.
894+ # (i.e. having a name, optional compose-file, and optional environment)
895+ # and 'jobs' is a list of job definitions (DefaultMunch stuff) for jobs
896+ # that have at least one test that runs in that group.
890897 #
891898 # See '_add_grouped_test()', which is used by _load() to build the map.
892899
@@ -988,8 +995,9 @@ def _run_grouped_tests(
988995 group_compose_file : Optional [str ] = None
989996 for index , grouped_test in enumerate (grouped_tests ):
990997
991- # For each grouped test we have a test-group definition,
992- # an 'ordinal', 'job name', 'job test' and the 'job' definition
998+ # For each grouped test we have a test-group definition [at index 0],
999+ # an 'ordinal' [1], 'collection' [2], 'job name' [3], 'job test' [4]
1000+ # and the 'job' definition [5]
9931001
9941002 # Start the group compose file?
9951003 if index == 0 and "compose" in grouped_test [0 ] and not args .dry_run :
@@ -1011,6 +1019,14 @@ def _run_grouped_tests(
10111019 )
10121020 break
10131021
1022+ # Does the test group define an environment?
1023+ test_group_environment : Dict [str , Any ] = {}
1024+ if grouped_test [0 ].environment :
1025+ for gt_env in grouped_test [0 ].environment :
1026+ key : str = list (gt_env .keys ())[0 ]
1027+ value : str = str (gt_env [key ])
1028+ test_group_environment [key ] = value
1029+
10141030 # The test
10151031 compose , test_result = _run_a_test (
10161032 args ,
@@ -1021,6 +1037,7 @@ def _run_grouped_tests(
10211037 grouped_test [5 ], # The job definition
10221038 run_group_name ,
10231039 grouped_test [1 ], # Ordinal
1040+ test_group_environment = test_group_environment ,
10241041 )
10251042
10261043 # Always try and teardown the test compose
0 commit comments