          handle_a, self.file_a = tempfile.mkstemp()
          handle_b, self.file_b = tempfile.mkstemp()
  
          # file_move_safe should raise an IOError exception if destination file exists and allow_overwrite is False
          self.assertRaises(IOError, lambda: file_move_safe(self.file_a, self.file_b, allow_overwrite=False))
  
          # should allow it and continue on if allow_overwrite is True
          self.assertIsNone(file_move_safe(self.file_a, self.file_b, allow_overwrite=True))
  
          os.close(handle_a)
 
</s> remove             self.assertRaises(Director.DoesNotExist, lambda: private_school.director)
 </s> add             with self.assertRaises(Director.DoesNotExist):
                private_school.director </s> remove         self.assertRaises(ObjectDoesNotExist, get_current_site, request)
 </s> add         with self.assertRaises(ObjectDoesNotExist):
            get_current_site(request) </s> remove         self.assertRaises(exception, force_text, MyString())
 </s> add         with self.assertRaises(exception):
            force_text(MyString()) </s> remove         self.assertRaises(InvalidSessionKey,
                          self.backend()._key_to_file, "a\\b\\c")
 </s> add         with self.assertRaises(InvalidSessionKey):
            self.backend()._key_to_file("a\\b\\c") </s> remove         self.assertRaises(ImproperlyConfigured, self.backend)
 </s> add         with self.assertRaises(ImproperlyConfigured):
            self.backend()
        with self.assertRaises(IOError):
            file_move_safe(self.file_a, self.file_b, allow_overwrite=False)
          handle_a, self.file_a = tempfile.mkstemp()
          handle_b, self.file_b = tempfile.mkstemp()
  
          # file_move_safe should raise an IOError exception if destination file exists and allow_overwrite is False
        with self.assertRaises(IOError):
            file_move_safe(self.file_a, self.file_b, allow_overwrite=False)
  
          # should allow it and continue on if allow_overwrite is True
          self.assertIsNone(file_move_safe(self.file_a, self.file_b, allow_overwrite=True))
  
          os.close(handle_a)
keep keep keep keep replace keep keep keep keep keep
 Refs #26022 -- Used context manager version of assertRaises in tests. 
tests/files/tests.py