Open chairmank opened 1 year ago
Agree it will be more convenient, we are working around as the below:
mock_message_class = mocker.patch('confluent_kafka.Message')
mock_message = mock_message_class.return_value
mock_message.key.return_value = serialized_key
mock_message.value.return_value = serialized_value
.....
Hi. I just came here to report the same. I had to work around by creating my own mock Message class that reimplements the whole interface for tests, but that is unproductive if every one has to do the same.
+1 I agree I have the same problem
+1 I have the same problem
+1 I also have the same problem
+1 I have the same problem.
+1, this is very annoying.
+1 same issue
+1
Description
This is an enhancement request to make it easier to write tests for user code that uses this client library. In unit tests, it would useful to be create synthetic
Message
instances without having to read them from a live Kafka cluster with aConsumer
.The current implementation of the
Message
type does not make it possible to instantiate aMessage
because thePyTypeObject MessageType
definition does not specify thetp_new
andtp_init
fields.In contrast, the
TopicPartitionType
definition does specify these fields, and we can instantiate aTopicPartition
.How to reproduce
Using confluent-kafka-python v2.0.2, I observe the following when I try to call the
__init__
method ofMessage
: