You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Skip Montanaro <sk...@gmail.com> on 2018/02/28 15:40:14 UTC
MockConsumer class for Python?
I think I've seen mention of a MockConsumer class, but the
kafka-python package I have available in my Conda setup doesn't seem
to have anything like that. Is this a Java-only thing or is there a
Python MockConsumer class I just haven't yet encountered in the wild?
I see this:
http://www.jesse-anderson.com/2016/11/unit-testing-kafka-consumers/
but that appears to be Java-specific.
Maybe it's not entirely necessary? Do people just unit test through a
development broker setup using fake messages sent to test-specific
topics?
Thx,
Skip Montanaro
Re: MockConsumer class for Python?
Posted by Sam Pegler <sa...@infectiousmedia.com>.
Why not just mock out the Kafka client in your tests and have it call a
function which yields a kafka message every call?
```
def consumer():
for _ in range(99):
yield KafkaMessage('key', 'value')mock_consumer =
mocker.patch.object(foo, 'consumer', consumer())
```
Is there any specific feature you're after?