code: def testDuplicateExtensionNumber(self):
      pool = descriptor_pool.DescriptorPool()
      factory = message_factory.MessageFactory(pool=pool)
  
      # Add Container message.
      f = descriptor_pb2.FileDescriptorProto()
      f.name = "google/protobuf/internal/container.proto"
      f.package = "google.protobuf.python.internal"
      msg = f.message_type.add()
      msg.name = "Container"
      rng = msg.extension_range.add()
      rng.start = 1
      rng.end = 10
      pool.Add(f)
      msgs = factory.GetMessages([f.name])
      self.assertIn("google.protobuf.python.internal.Container", msgs)
  
      # Extend container.
      f = descriptor_pb2.FileDescriptorProto()
      f.name = "google/protobuf/internal/extension.proto"
      f.package = "google.protobuf.python.internal"
      f.dependency.append("google/protobuf/internal/container.proto")
      msg = f.message_type.add()
      msg.name = "Extension"
      ext = msg.extension.add()
      ext.name = "extension_field"
      ext.number = 2
      ext.label = descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL
      ext.type_name = "Extension"
      ext.extendee = "Container"
      pool.Add(f)
      msgs = factory.GetMessages([f.name])
      self.assertIn("google.protobuf.python.internal.Extension", msgs)
  
      # Add Duplicate extending the same field number.
      f = descriptor_pb2.FileDescriptorProto()
      f.name = "google/protobuf/internal/duplicate.proto"
      f.package = "google.protobuf.python.internal"
      f.dependency.append("google/protobuf/internal/container.proto")
      msg = f.message_type.add()
      msg.name = "Duplicate"
      ext = msg.extension.add()
      ext.name = "extension_field"
      ext.number = 2
      ext.label = descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL
      ext.type_name = "Duplicate"
      ext.extendee = "Container"
      pool.Add(f)
  
      with self.assertRaises(Exception) as cm:
          factory.GetMessages([f.name])
  
      self.assertIsInstance(cm.exception, (AssertionError, ValueError))
  
file_path: coremltools/deps/protobuf/python/google/protobuf/internal/message_factory_test.py
imports: from google.protobuf import descriptor_pb2
  from google.protobuf.internal import factory_test1_pb2
  from google.protobuf.internal import factory_test2_pb2
  from google.protobuf import descriptor_database
  from google.protobuf import descriptor_pool
  from google.protobuf import message_factory
label_desc: Use image node_id 5 for calling the MessageFactoryTest obj's underlying member method code with example usage: obj.testDuplicateExtensionNumber() without return types