              with extend_sys_path(temp_dir):
                  new_module = os.path.basename(target_dir) + '.migrations'
                  with self.settings(MIGRATION_MODULES={app_label: new_module}):
                      yield target_migrations_dir
  
          finally:
              shutil.rmtree(temp_dir)
 
</s> remove         temp_dir = tempfile.mkdtemp()
        try:
 </s> add         with tempfile.TemporaryDirectory() as temp_dir: </s> remove         tmp_dir = tempfile.mkdtemp()
        try:
 </s> add         with tempfile.TemporaryDirectory() as tmp_dir: </s> remove         with self.settings(STATICFILES_DIRS=[static_dir]):
            output = self._collectstatic_output(clear=True)
        self.assertIn(self.warning_string, output)
 </s> add             with self.settings(STATICFILES_DIRS=[static_dir]):
                output = self._collectstatic_output(clear=True)
            self.assertIn(self.warning_string, output) </s> remove         static_dir = tempfile.mkdtemp(prefix='collectstatic_empty_staticdir_test')
        with override_settings(STATIC_ROOT=static_dir):
            call_command('collectstatic', interactive=True, stdout=stdout)
        shutil.rmtree(static_dir)
 </s> add         with tempfile.TemporaryDirectory(prefix='collectstatic_empty_staticdir_test') as static_dir:
            with override_settings(STATIC_ROOT=static_dir):
                call_command('collectstatic', interactive=True, stdout=stdout) </s> remove         static_dir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, static_dir)

        duplicate = os.path.join(static_dir, 'test', 'file.txt')
        os.mkdir(os.path.dirname(duplicate))
        with open(duplicate, 'w+') as f:
            f.write('duplicate of file.txt')
 </s> add         with tempfile.TemporaryDirectory() as static_dir:
            duplicate = os.path.join(static_dir, 'test', 'file.txt')
            os.mkdir(os.path.dirname(duplicate))
            with open(duplicate, 'w+') as f:
                f.write('duplicate of file.txt')
              with extend_sys_path(temp_dir):
                  new_module = os.path.basename(target_dir) + '.migrations'
                  with self.settings(MIGRATION_MODULES={app_label: new_module}):
                      yield target_migrations_dir



keep keep keep keep replace replace replace
 Refs #23919 -- Replaced tempfile.mkdtemp() with TemporaryDirectory() context manager. 
tests/migrations/test_base.py