@@ -586,6 +586,86 @@ def test_e_test_inferred_compiler(self):
586586 )
587587 self .assertEqual (os .path .split (result )[1 ], "gnuX" )
588588
589+ def test_f_baseline_not_cleared_on_failure (self ):
590+ """
591+ Verify that existing baselines are preserved when a regeneration attempt
592+ fails. Before the fix, clear_folder ran in the TestScheduler constructor
593+ (before the test executed), so a failing run left the case with no
594+ baselines. After the fix, clearing is deferred to _generate_baseline_impl
595+ which is only reached when the run phase succeeds.
596+
597+ Steps:
598+ 1. Generate baselines with TESTRUNFAIL_PASS set (test passes).
599+ 2. Attempt regeneration WITHOUT TESTRUNFAIL_PASS (run fails).
600+ Baselines must remain intact.
601+ 3. Compare with TESTRUNFAIL_PASS set – should succeed because the
602+ original baselines from step 1 are still present.
603+ """
604+ test_name = "TESTRUNFAIL_P1.f19_g16.A"
605+ if self ._config .create_test_flag_mode == "e3sm" :
606+ genargs = ["-g" , "-o" , "-b" , self ._baseline_name , test_name ]
607+ compargs = ["-c" , "-b" , self ._baseline_name , test_name ]
608+ else :
609+ genargs = ["-g" , self ._baseline_name , "-o" , test_name ]
610+ compargs = ["-c" , self ._baseline_name , test_name ]
611+
612+ # Step 1: Generate initial baselines with a passing run.
613+ os .environ ["TESTRUNFAIL_PASS" ] = "True"
614+ try :
615+ self ._create_test (genargs )
616+ finally :
617+ del os .environ ["TESTRUNFAIL_PASS" ]
618+
619+ baseline_dir = os .path .join (self ._baseline_area , self ._baseline_name )
620+ self .assertTrue (
621+ os .path .isdir (baseline_dir ), "Baseline dir should exist after generation"
622+ )
623+ baseline_cases = glob .glob (os .path .join (baseline_dir , "*TESTRUNFAIL*" ))
624+ self .assertEqual (
625+ len (baseline_cases ), 1 , "Expected exactly one TESTRUNFAIL baseline dir"
626+ )
627+
628+ # Collect the set of regular files created by the baseline generation.
629+ # CaseDocs is a directory managed separately by the namelist phase and
630+ # may be legitimately refreshed during a subsequent SETUP, so we only
631+ # track files here.
632+ baseline_case_dir = baseline_cases [0 ]
633+ baseline_files_before = {
634+ f
635+ for f in os .listdir (baseline_case_dir )
636+ if os .path .isfile (os .path .join (baseline_case_dir , f ))
637+ }
638+ self .assertGreater (
639+ len (baseline_files_before ),
640+ 0 ,
641+ "Baseline must contain at least one file after generation" ,
642+ )
643+
644+ # Step 2: Attempt regeneration WITHOUT TESTRUNFAIL_PASS – run will fail.
645+ # Our fix ensures that baseline files are NOT cleared before the run
646+ # completes successfully.
647+ self ._create_test (genargs , run_errors = True )
648+
649+ baseline_cases_after = glob .glob (os .path .join (baseline_dir , "*TESTRUNFAIL*" ))
650+ self .assertEqual (len (baseline_cases_after ), 1 )
651+ baseline_files_after = {
652+ f
653+ for f in os .listdir (baseline_cases_after [0 ])
654+ if os .path .isfile (os .path .join (baseline_cases_after [0 ], f ))
655+ }
656+ self .assertEqual (
657+ baseline_files_before ,
658+ baseline_files_after ,
659+ msg = "Baseline files were modified by a failed generation attempt" ,
660+ )
661+
662+ # Step 3: Comparison against the preserved baselines should succeed.
663+ os .environ ["TESTRUNFAIL_PASS" ] = "True"
664+ try :
665+ self ._create_test (compargs )
666+ finally :
667+ del os .environ ["TESTRUNFAIL_PASS" ]
668+
589669
590670if __name__ == "__main__" :
591671 unittest .main ()
0 commit comments