  
          Director.objects.use_for_related_fields = True
          try:
              private_school = School._base_manager.get(pk=private_school.pk)
              self.assertRaises(Director.DoesNotExist, lambda: private_school.director)
          finally:
              Director.objects.use_for_related_fields = False
  
      def test_hasattr_related_object(self):
          # The exception raised on attribute access when a related object
 
</s> remove             self.assertRaises(School.DoesNotExist, lambda: private_director.school)
 </s> add             with self.assertRaises(School.DoesNotExist):
                private_director.school </s> remove         self.assertRaises(IOError, lambda: file_move_safe(self.file_a, self.file_b, allow_overwrite=False))
 </s> add         with self.assertRaises(IOError):
            file_move_safe(self.file_a, self.file_b, allow_overwrite=False) </s> remove         self.assertRaises(
            AttributeError, getattr, post, "attached_%(class)s_set"
        )
 </s> add         with self.assertRaises(AttributeError):
            getattr(post, "attached_%(class)s_set") </s> remove         self.assertRaises(ContentNotRenderedError, lambda: response.content)
 </s> add         with self.assertRaises(ContentNotRenderedError):
            response.content </s> remove         self.assertRaises(PermissionDenied, AView.as_view(), request)
 </s> add         with self.assertRaises(PermissionDenied):
            AView.as_view()(request)
            with self.assertRaises(Director.DoesNotExist):
                private_school.director
  
          Director.objects.use_for_related_fields = True
          try:
              private_school = School._base_manager.get(pk=private_school.pk)
            with self.assertRaises(Director.DoesNotExist):
                private_school.director
          finally:
              Director.objects.use_for_related_fields = False
  
      def test_hasattr_related_object(self):
          # The exception raised on attribute access when a related object
keep keep keep keep replace keep keep keep keep keep
 Refs #26022 -- Used context manager version of assertRaises in tests. 
tests/one_to_one/tests.py