              raise AssertionError('this function should never be called')
  
          try:
              connection.set_autocommit(False)
              with self.assertRaises(transaction.TransactionManagementError):
                  transaction.on_commit(should_never_be_called)
          finally:
              connection.set_autocommit(True)
 
</s> remove         with self.assertRaises(TemplateSyntaxError):
 </s> add         msg = "Variables and attributes may not begin with underscores: 'article._hidden'"
        with self.assertRaisesMessage(TemplateSyntaxError, msg): </s> remove             with self.assertRaises(ImproperlyConfigured):
 </s> add             msg = (
                "Connection 'tz' cannot set TIME_ZONE because its engine "
                "handles time zones conversions natively."
            )
            with self.assertRaisesMessage(ImproperlyConfigured, msg): </s> remove             with self.assertRaises(transaction.TransactionManagementError):
 </s> add             with self.assertRaisesMessage(transaction.TransactionManagementError, self.forbidden_atomic_msg): </s> remove             with self.assertRaises(transaction.TransactionManagementError):
 </s> add             with self.assertRaisesMessage(transaction.TransactionManagementError, self.forbidden_atomic_msg): </s> remove         with self.assertRaises(ImproperlyConfigured):
 </s> add         msg = 'The model Location is abstract, so it cannot be registered with admin.'
        with self.assertRaisesMessage(ImproperlyConfigured, msg):
            msg = 'on_commit() cannot be used in manual transaction management'
            with self.assertRaisesMessage(transaction.TransactionManagementError, msg):
              raise AssertionError('this function should never be called')
  
          try:
              connection.set_autocommit(False)
            msg = 'on_commit() cannot be used in manual transaction management'
            with self.assertRaisesMessage(transaction.TransactionManagementError, msg):
                  transaction.on_commit(should_never_be_called)
          finally:
              connection.set_autocommit(True)
keep keep keep keep replace keep keep keep
 Used assertRaisesMessage() to test Django's error messages. 
tests/transaction_hooks/tests.py