#!/usr/bin/env python3 # Test file demonstrating issues from # https://github.com/protocolbuffers/protobuf/pull/5166 # Try running with PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python # and with PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp import subprocess proto_definition = """ syntax = "proto2"; message TestMessage { optional int32 value = 1; } """ with open('test.proto', 'w') as f: f.write(proto_definition) subprocess.check_call(['protoc', '--python_out=.', 'test.proto']) import test_pb2 # noqa test_message = test_pb2.TestMessage() print(test_message.ParseFromString(b'test'))