Protobuf

Testsuite provides matchers and utilities for working with protobuf messages in tests. To use them, install the protobuf extra:

pip install yandex-taxi-testsuite[protobuf]

Enable the plugin by adding it to pytest_plugins in your conftest.py:

pytest_plugins = [
    'testsuite.pytest_plugin',
    'testsuite.protobuf.pytest_plugin',
]

The plugin registers compare visitors so that when two protobuf messages (or a message and a matcher) are compared with assert, the failure output shows human-readable field diffs rather than raw byte strings.

Matchers

ProtobufDict

Compares a protobuf message against a plain dict. The message is converted to a dict via testsuite.protobuf.utils.message_to_dict() (which uses preserving_proto_field_name=True) before the comparison.

from testsuite.protobuf.matching import ProtobufDict

def test_response(my_proto_message):
    assert my_proto_message == ProtobufDict({'field': 'value', 'count': 1})

PartialProtobufDict

Like ProtobufDict, but only checks the keys present in the expected dict — extra fields in the actual message are ignored.

from testsuite.protobuf.matching import PartialProtobufDict

def test_response(my_proto_message):
    # passes as long as 'field' == 'value', ignores other fields
    assert my_proto_message == PartialProtobufDict({'field': 'value'})

Classes

class testsuite.protobuf.matching.ProtobufDict(d: dict)[source]

Compare a protobuf message against an expected dict.

class testsuite.protobuf.matching.PartialProtobufDict(d: dict)[source]

Partially compare a protobuf message against an expected dict.

Utilities

testsuite.protobuf.utils.message_to_dict(msg) dict[source]

Convert a protobuf message to a plain dict, preserving field names.