      def test_warning(self):
          """
          There is a warning when there are duplicate destinations.
          """
          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')
  
          with self.settings(STATICFILES_DIRS=[static_dir]):
              output = self._collectstatic_output(clear=True)
          self.assertIn(self.warning_string, output)
  
 
</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         os.remove(duplicate)
 </s> add             os.remove(duplicate) </s> remove         tdir = sys_tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, tdir, True)

        # This file contains Chinese symbols and an accented char in the name.
        with open(os.path.join(tdir, UNICODE_FILENAME), 'w+b') as file1:
            file1.write(b'b' * (2 ** 10))
            file1.seek(0)

            post_data = {
                'file_unicode': file1,
            }

            response = self.client.post('/unicode_name/', post_data)

        self.assertEqual(response.status_code, 200)
 </s> add         with sys_tempfile.TemporaryDirectory() as temp_dir:
            # This file contains Chinese symbols and an accented char in the name.
            with open(os.path.join(temp_dir, UNICODE_FILENAME), 'w+b') as file1:
                file1.write(b'b' * (2 ** 10))
                file1.seek(0)
                response = self.client.post('/unicode_name/', {'file_unicode': file1})
            self.assertEqual(response.status_code, 200) </s> remove         # Make sure the warning went away again.
        with self.settings(STATICFILES_DIRS=[static_dir]):
            output = self._collectstatic_output(clear=True)
        self.assertNotIn(self.warning_string, output)
 </s> add             # Make sure the warning went away again.
            with self.settings(STATICFILES_DIRS=[static_dir]):
                output = self._collectstatic_output(clear=True)
            self.assertNotIn(self.warning_string, output)
        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')
      def test_warning(self):
          """
          There is a warning when there are duplicate destinations.
          """
        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 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 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 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 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 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 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 self.settings(STATICFILES_DIRS=[static_dir]):
              output = self._collectstatic_output(clear=True)
          self.assertIn(self.warning_string, output)
  
keep keep keep keep replace replace replace replace replace replace replace keep keep keep keep keep
 Refs #23919 -- Replaced tempfile.mkdtemp() with TemporaryDirectory() context manager. 
tests/staticfiles_tests/test_management.py