We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
settings from env_test are not being reapplied to tests
It seems that some recent change causes the settings from env_test.xml not to be applied when a test is resubmitted.   This is supposed to be tested in scripts_regression_tests so a second question is - why is that test not failing?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scripts/lib/CIME/case/case_submit.py`
Content:
```
1 #!/usr/bin/env python
2 
3 """
4 case.submit - Submit a cesm workflow to the queueing system or run it
5 if there is no queueing system.  A cesm workflow may include multiple
6 jobs.
7 submit, check_case and check_da_settings are members of class Case in file case.py
8 """
9 import socket
10 from CIME.XML.standard_module_setup import *
11 from CIME.utils                     import expect, run_and_log_case_status, verbatim_success_msg
12 from CIME.locked_files              import unlock_file, lock_file
13 from CIME.test_status               import *
14 
15 logger = logging.getLogger(__name__)
16 
17 def _submit(case, job=None, no_batch=False, prereq=None, resubmit=False,
18             skip_pnl=False, mail_user=None, mail_type=None, batch_args=None):
19     if job is None:
20         job = case.get_primary_job()
21 
22     rundir = case.get_value("RUNDIR")
23     continue_run = case.get_value("CONTINUE_RUN")
24     expect(os.path.isdir(rundir) or not continue_run,
25            " CONTINUE_RUN is true but RUNDIR {} does not exist".format(rundir))
26 
27     # if case.submit is called with the no_batch flag then we assume that this
28     # flag will stay in effect for the duration of the RESUBMITs
29     env_batch = case.get_env("batch")
30     if resubmit:
31         if env_batch.get_batch_system_type() == "none":
32             no_batch = True
33 
34         # This is a resubmission, do not reinitialize test values
35         if job == "case.test":
36             case.set_value("IS_FIRST_RUN", False)
37 
38         resub = case.get_value("RESUBMIT")
39         logger.info("Submitting job '{}', resubmit={:d}".format(job, resub))
40         case.set_value("RESUBMIT", resub-1)
41         if case.get_value("RESUBMIT_SETS_CONTINUE_RUN"):
42             case.set_value("CONTINUE_RUN", True)
43 
44     else:
45         if job == "case.test":
46             case.set_value("IS_FIRST_RUN", True)
47 
48         if no_batch:
49             batch_system = "none"
50         else:
51             batch_system = env_batch.get_batch_system_type()
52 
53         case.set_value("BATCH_SYSTEM", batch_system)
54 
55         env_batch_has_changed = False
56         try:
57             case.check_lockedfile(os.path.basename(env_batch.filename))
58         except SystemExit:
59             env_batch_has_changed = True
60 
61         if env_batch.get_batch_system_type() != "none" and env_batch_has_changed:
62             # May need to regen batch files if user made batch setting changes (e.g. walltime, queue, etc)
63             logger.warning(\
64 """
65 env_batch.xml appears to have changed, regenerating batch scripts
66 manual edits to these file will be lost!
67 """)
68             env_batch.make_all_batch_files(case)
69 
70         unlock_file(os.path.basename(env_batch.filename))
71         lock_file(os.path.basename(env_batch.filename))
72 
73         if job == case.get_primary_job():
74             case.check_case()
75             case.check_DA_settings()
76             if case.get_value("MACH") == "mira":
77                 with open(".original_host", "w") as fd:
78                     fd.write( socket.gethostname())
79 
80     #Load Modules
81     case.load_env()
82 
83     case.flush()
84 
85     logger.warning("submit_jobs {}".format(job))
86     job_ids = case.submit_jobs(no_batch=no_batch, job=job, skip_pnl=skip_pnl,
87                                prereq=prereq, mail_user=mail_user,
88                                mail_type=mail_type, batch_args=batch_args)
89 
90     xml_jobids = []
91     for jobname, jobid in job_ids.items():
92         logger.info("Submitted job {} with id {}".format(jobname, jobid))
93         if jobid:
94             xml_jobids.append("{}:{}".format(jobname, jobid))
95 
96     xml_jobid_text = ", ".join(xml_jobids)
97     if xml_jobid_text:
98         case.set_value("JOB_IDS", xml_jobid_text)
99 
100     return xml_jobid_text
101 
102 def submit(self, job=None, no_batch=False, prereq=None, resubmit=False,
103            skip_pnl=False, mail_user=None, mail_type=None, batch_args=None):
104     if self.get_value("TEST"):
105         caseroot = self.get_value("CASEROOT")
106         casebaseid = self.get_value("CASEBASEID")
107         # This should take care of the race condition where the submitted job
108         # begins immediately and tries to set RUN phase. We proactively assume
109         # a passed SUBMIT phase. If this state is already PASS, don't set it again
110         # because then we'll lose RUN phase info if it's there. This info is important
111         # for system_tests_common to know if it needs to reinitialize the test or not.
112         with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:
113             phase_status = ts.get_status(SUBMIT_PHASE)
114             if phase_status != TEST_PASS_STATUS:
115                 ts.set_status(SUBMIT_PHASE, TEST_PASS_STATUS)
116 
117     try:
118         functor = lambda: _submit(self, job=job, no_batch=no_batch, prereq=prereq,
119                                   resubmit=resubmit, skip_pnl=skip_pnl,
120                                   mail_user=mail_user, mail_type=mail_type,
121                                   batch_args=batch_args)
122         run_and_log_case_status(functor, "case.submit", caseroot=self.get_value("CASEROOT"),
123                                 custom_success_msg_functor=verbatim_success_msg)
124     except:
125         # If something failed in the batch system, make sure to mark
126         # the test as failed if we are running a test.
127         if self.get_value("TEST"):
128             with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:
129                 ts.set_status(SUBMIT_PHASE, TEST_FAIL_STATUS)
130 
131         raise
132 
133 def check_case(self):
134     self.check_lockedfiles()
135     self.create_namelists() # Must be called before check_all_input_data
136     logger.info("Checking that inputdata is available as part of case submission")
137     self.check_all_input_data()
138 
139     expect(self.get_value("BUILD_COMPLETE"), "Build complete is "
140            "not True please rebuild the model by calling case.build")
141     logger.info("Check case OK")
142 
143 def check_DA_settings(self):
144     script = self.get_value("DATA_ASSIMILATION_SCRIPT")
145     cycles = self.get_value("DATA_ASSIMILATION_CYCLES")
146     if len(script) > 0 and os.path.isfile(script) and cycles > 0:
147         logger.info("Data Assimilation enabled using script {} with {:d} cycles".format(script,cycles))
148
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scripts/lib/CIME/case/case_submit.py b/scripts/lib/CIME/case/case_submit.py
--- a/scripts/lib/CIME/case/case_submit.py
+++ b/scripts/lib/CIME/case/case_submit.py
@@ -20,9 +20,10 @@
         job = case.get_primary_job()
 
     rundir = case.get_value("RUNDIR")
-    continue_run = case.get_value("CONTINUE_RUN")
-    expect(os.path.isdir(rundir) or not continue_run,
-           " CONTINUE_RUN is true but RUNDIR {} does not exist".format(rundir))
+    if job != "case.test":
+        continue_run = case.get_value("CONTINUE_RUN")
+        expect(os.path.isdir(rundir) or not continue_run,
+               " CONTINUE_RUN is true but RUNDIR {} does not exist".format(rundir))
 
     # if case.submit is called with the no_batch flag then we assume that this
     # flag will stay in effect for the duration of the RESUBMITs

{"golden_diff": "diff --git a/scripts/lib/CIME/case/case_submit.py b/scripts/lib/CIME/case/case_submit.py\n--- a/scripts/lib/CIME/case/case_submit.py\n+++ b/scripts/lib/CIME/case/case_submit.py\n@@ -20,9 +20,10 @@\n         job = case.get_primary_job()\n \n     rundir = case.get_value(\"RUNDIR\")\n-    continue_run = case.get_value(\"CONTINUE_RUN\")\n-    expect(os.path.isdir(rundir) or not continue_run,\n-           \" CONTINUE_RUN is true but RUNDIR {} does not exist\".format(rundir))\n+    if job != \"case.test\":\n+        continue_run = case.get_value(\"CONTINUE_RUN\")\n+        expect(os.path.isdir(rundir) or not continue_run,\n+               \" CONTINUE_RUN is true but RUNDIR {} does not exist\".format(rundir))\n \n     # if case.submit is called with the no_batch flag then we assume that this\n     # flag will stay in effect for the duration of the RESUBMITs\n", "issue": "settings from env_test are not being reapplied to tests\nIt seems that some recent change causes the settings from env_test.xml not to be applied when a test is resubmitted.   This is supposed to be tested in scripts_regression_tests so a second question is - why is that test not failing?\n", "before_files": [{"content": "#!/usr/bin/env python\n\n\"\"\"\ncase.submit - Submit a cesm workflow to the queueing system or run it\nif there is no queueing system.  A cesm workflow may include multiple\njobs.\nsubmit, check_case and check_da_settings are members of class Case in file case.py\n\"\"\"\nimport socket\nfrom CIME.XML.standard_module_setup import *\nfrom CIME.utils                     import expect, run_and_log_case_status, verbatim_success_msg\nfrom CIME.locked_files              import unlock_file, lock_file\nfrom CIME.test_status               import *\n\nlogger = logging.getLogger(__name__)\n\ndef _submit(case, job=None, no_batch=False, prereq=None, resubmit=False,\n            skip_pnl=False, mail_user=None, mail_type=None, batch_args=None):\n    if job is None:\n        job = case.get_primary_job()\n\n    rundir = case.get_value(\"RUNDIR\")\n    continue_run = case.get_value(\"CONTINUE_RUN\")\n    expect(os.path.isdir(rundir) or not continue_run,\n           \" CONTINUE_RUN is true but RUNDIR {} does not exist\".format(rundir))\n\n    # if case.submit is called with the no_batch flag then we assume that this\n    # flag will stay in effect for the duration of the RESUBMITs\n    env_batch = case.get_env(\"batch\")\n    if resubmit:\n        if env_batch.get_batch_system_type() == \"none\":\n            no_batch = True\n\n        # This is a resubmission, do not reinitialize test values\n        if job == \"case.test\":\n            case.set_value(\"IS_FIRST_RUN\", False)\n\n        resub = case.get_value(\"RESUBMIT\")\n        logger.info(\"Submitting job '{}', resubmit={:d}\".format(job, resub))\n        case.set_value(\"RESUBMIT\", resub-1)\n        if case.get_value(\"RESUBMIT_SETS_CONTINUE_RUN\"):\n            case.set_value(\"CONTINUE_RUN\", True)\n\n    else:\n        if job == \"case.test\":\n            case.set_value(\"IS_FIRST_RUN\", True)\n\n        if no_batch:\n            batch_system = \"none\"\n        else:\n            batch_system = env_batch.get_batch_system_type()\n\n        case.set_value(\"BATCH_SYSTEM\", batch_system)\n\n        env_batch_has_changed = False\n        try:\n            case.check_lockedfile(os.path.basename(env_batch.filename))\n        except SystemExit:\n            env_batch_has_changed = True\n\n        if env_batch.get_batch_system_type() != \"none\" and env_batch_has_changed:\n            # May need to regen batch files if user made batch setting changes (e.g. walltime, queue, etc)\n            logger.warning(\\\n\"\"\"\nenv_batch.xml appears to have changed, regenerating batch scripts\nmanual edits to these file will be lost!\n\"\"\")\n            env_batch.make_all_batch_files(case)\n\n        unlock_file(os.path.basename(env_batch.filename))\n        lock_file(os.path.basename(env_batch.filename))\n\n        if job == case.get_primary_job():\n            case.check_case()\n            case.check_DA_settings()\n            if case.get_value(\"MACH\") == \"mira\":\n                with open(\".original_host\", \"w\") as fd:\n                    fd.write( socket.gethostname())\n\n    #Load Modules\n    case.load_env()\n\n    case.flush()\n\n    logger.warning(\"submit_jobs {}\".format(job))\n    job_ids = case.submit_jobs(no_batch=no_batch, job=job, skip_pnl=skip_pnl,\n                               prereq=prereq, mail_user=mail_user,\n                               mail_type=mail_type, batch_args=batch_args)\n\n    xml_jobids = []\n    for jobname, jobid in job_ids.items():\n        logger.info(\"Submitted job {} with id {}\".format(jobname, jobid))\n        if jobid:\n            xml_jobids.append(\"{}:{}\".format(jobname, jobid))\n\n    xml_jobid_text = \", \".join(xml_jobids)\n    if xml_jobid_text:\n        case.set_value(\"JOB_IDS\", xml_jobid_text)\n\n    return xml_jobid_text\n\ndef submit(self, job=None, no_batch=False, prereq=None, resubmit=False,\n           skip_pnl=False, mail_user=None, mail_type=None, batch_args=None):\n    if self.get_value(\"TEST\"):\n        caseroot = self.get_value(\"CASEROOT\")\n        casebaseid = self.get_value(\"CASEBASEID\")\n        # This should take care of the race condition where the submitted job\n        # begins immediately and tries to set RUN phase. We proactively assume\n        # a passed SUBMIT phase. If this state is already PASS, don't set it again\n        # because then we'll lose RUN phase info if it's there. This info is important\n        # for system_tests_common to know if it needs to reinitialize the test or not.\n        with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:\n            phase_status = ts.get_status(SUBMIT_PHASE)\n            if phase_status != TEST_PASS_STATUS:\n                ts.set_status(SUBMIT_PHASE, TEST_PASS_STATUS)\n\n    try:\n        functor = lambda: _submit(self, job=job, no_batch=no_batch, prereq=prereq,\n                                  resubmit=resubmit, skip_pnl=skip_pnl,\n                                  mail_user=mail_user, mail_type=mail_type,\n                                  batch_args=batch_args)\n        run_and_log_case_status(functor, \"case.submit\", caseroot=self.get_value(\"CASEROOT\"),\n                                custom_success_msg_functor=verbatim_success_msg)\n    except:\n        # If something failed in the batch system, make sure to mark\n        # the test as failed if we are running a test.\n        if self.get_value(\"TEST\"):\n            with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:\n                ts.set_status(SUBMIT_PHASE, TEST_FAIL_STATUS)\n\n        raise\n\ndef check_case(self):\n    self.check_lockedfiles()\n    self.create_namelists() # Must be called before check_all_input_data\n    logger.info(\"Checking that inputdata is available as part of case submission\")\n    self.check_all_input_data()\n\n    expect(self.get_value(\"BUILD_COMPLETE\"), \"Build complete is \"\n           \"not True please rebuild the model by calling case.build\")\n    logger.info(\"Check case OK\")\n\ndef check_DA_settings(self):\n    script = self.get_value(\"DATA_ASSIMILATION_SCRIPT\")\n    cycles = self.get_value(\"DATA_ASSIMILATION_CYCLES\")\n    if len(script) > 0 and os.path.isfile(script) and cycles > 0:\n        logger.info(\"Data Assimilation enabled using script {} with {:d} cycles\".format(script,cycles))\n", "path": "scripts/lib/CIME/case/case_submit.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\n\"\"\"\ncase.submit - Submit a cesm workflow to the queueing system or run it\nif there is no queueing system.  A cesm workflow may include multiple\njobs.\nsubmit, check_case and check_da_settings are members of class Case in file case.py\n\"\"\"\nimport socket\nfrom CIME.XML.standard_module_setup import *\nfrom CIME.utils                     import expect, run_and_log_case_status, verbatim_success_msg\nfrom CIME.locked_files              import unlock_file, lock_file\nfrom CIME.test_status               import *\n\nlogger = logging.getLogger(__name__)\n\ndef _submit(case, job=None, no_batch=False, prereq=None, resubmit=False,\n            skip_pnl=False, mail_user=None, mail_type=None, batch_args=None):\n    if job is None:\n        job = case.get_primary_job()\n\n    rundir = case.get_value(\"RUNDIR\")\n    if job != \"case.test\":\n        continue_run = case.get_value(\"CONTINUE_RUN\")\n        expect(os.path.isdir(rundir) or not continue_run,\n               \" CONTINUE_RUN is true but RUNDIR {} does not exist\".format(rundir))\n\n    # if case.submit is called with the no_batch flag then we assume that this\n    # flag will stay in effect for the duration of the RESUBMITs\n    env_batch = case.get_env(\"batch\")\n    if resubmit:\n        if env_batch.get_batch_system_type() == \"none\":\n            no_batch = True\n\n        # This is a resubmission, do not reinitialize test values\n        if job == \"case.test\":\n            case.set_value(\"IS_FIRST_RUN\", False)\n\n        resub = case.get_value(\"RESUBMIT\")\n        logger.info(\"Submitting job '{}', resubmit={:d}\".format(job, resub))\n        case.set_value(\"RESUBMIT\", resub-1)\n        if case.get_value(\"RESUBMIT_SETS_CONTINUE_RUN\"):\n            case.set_value(\"CONTINUE_RUN\", True)\n\n    else:\n        if job == \"case.test\":\n            case.set_value(\"IS_FIRST_RUN\", True)\n\n        if no_batch:\n            batch_system = \"none\"\n        else:\n            batch_system = env_batch.get_batch_system_type()\n\n        case.set_value(\"BATCH_SYSTEM\", batch_system)\n\n        env_batch_has_changed = False\n        try:\n            case.check_lockedfile(os.path.basename(env_batch.filename))\n        except SystemExit:\n            env_batch_has_changed = True\n\n        if env_batch.get_batch_system_type() != \"none\" and env_batch_has_changed:\n            # May need to regen batch files if user made batch setting changes (e.g. walltime, queue, etc)\n            logger.warning(\\\n\"\"\"\nenv_batch.xml appears to have changed, regenerating batch scripts\nmanual edits to these file will be lost!\n\"\"\")\n            env_batch.make_all_batch_files(case)\n\n        unlock_file(os.path.basename(env_batch.filename))\n        lock_file(os.path.basename(env_batch.filename))\n\n        if job == case.get_primary_job():\n            case.check_case()\n            case.check_DA_settings()\n            if case.get_value(\"MACH\") == \"mira\":\n                with open(\".original_host\", \"w\") as fd:\n                    fd.write( socket.gethostname())\n\n    #Load Modules\n    case.load_env()\n\n    case.flush()\n\n    logger.warning(\"submit_jobs {}\".format(job))\n    job_ids = case.submit_jobs(no_batch=no_batch, job=job, skip_pnl=skip_pnl,\n                               prereq=prereq, mail_user=mail_user,\n                               mail_type=mail_type, batch_args=batch_args)\n\n    xml_jobids = []\n    for jobname, jobid in job_ids.items():\n        logger.info(\"Submitted job {} with id {}\".format(jobname, jobid))\n        if jobid:\n            xml_jobids.append(\"{}:{}\".format(jobname, jobid))\n\n    xml_jobid_text = \", \".join(xml_jobids)\n    if xml_jobid_text:\n        case.set_value(\"JOB_IDS\", xml_jobid_text)\n\n    return xml_jobid_text\n\ndef submit(self, job=None, no_batch=False, prereq=None, resubmit=False,\n           skip_pnl=False, mail_user=None, mail_type=None, batch_args=None):\n    if self.get_value(\"TEST\"):\n        caseroot = self.get_value(\"CASEROOT\")\n        casebaseid = self.get_value(\"CASEBASEID\")\n        # This should take care of the race condition where the submitted job\n        # begins immediately and tries to set RUN phase. We proactively assume\n        # a passed SUBMIT phase. If this state is already PASS, don't set it again\n        # because then we'll lose RUN phase info if it's there. This info is important\n        # for system_tests_common to know if it needs to reinitialize the test or not.\n        with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:\n            phase_status = ts.get_status(SUBMIT_PHASE)\n            if phase_status != TEST_PASS_STATUS:\n                ts.set_status(SUBMIT_PHASE, TEST_PASS_STATUS)\n\n    try:\n        functor = lambda: _submit(self, job=job, no_batch=no_batch, prereq=prereq,\n                                  resubmit=resubmit, skip_pnl=skip_pnl,\n                                  mail_user=mail_user, mail_type=mail_type,\n                                  batch_args=batch_args)\n        run_and_log_case_status(functor, \"case.submit\", caseroot=self.get_value(\"CASEROOT\"),\n                                custom_success_msg_functor=verbatim_success_msg)\n    except:\n        # If something failed in the batch system, make sure to mark\n        # the test as failed if we are running a test.\n        if self.get_value(\"TEST\"):\n            with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:\n                ts.set_status(SUBMIT_PHASE, TEST_FAIL_STATUS)\n\n        raise\n\ndef check_case(self):\n    self.check_lockedfiles()\n    self.create_namelists() # Must be called before check_all_input_data\n    logger.info(\"Checking that inputdata is available as part of case submission\")\n    self.check_all_input_data()\n\n    expect(self.get_value(\"BUILD_COMPLETE\"), \"Build complete is \"\n           \"not True please rebuild the model by calling case.build\")\n    logger.info(\"Check case OK\")\n\ndef check_DA_settings(self):\n    script = self.get_value(\"DATA_ASSIMILATION_SCRIPT\")\n    cycles = self.get_value(\"DATA_ASSIMILATION_CYCLES\")\n    if len(script) > 0 and os.path.isfile(script) and cycles > 0:\n        logger.info(\"Data Assimilation enabled using script {} with {:d} cycles\".format(script,cycles))\n", "path": "scripts/lib/CIME/case/case_submit.py"}]}