Skip to content

Commit 52c31c6

Browse files
rnpridgeonRyan P
authored andcommitted
Update Consumer and Producer test exception assertions with pytest.match
1 parent 576c087 commit 52c31c6

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

tests/test_Consumer.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def test_multiple_close_throw_exception():
226226

227227
with pytest.raises(RuntimeError) as ex:
228228
c.close()
229-
assert 'Consumer already closed' == str(ex.value)
229+
assert ex.match('Consumer already closed')
230230

231231

232232
def test_any_method_after_close_throws_exception():
@@ -244,51 +244,51 @@ def test_any_method_after_close_throws_exception():
244244

245245
with pytest.raises(RuntimeError) as ex:
246246
c.subscribe(['test'])
247-
assert 'Consumer closed' == str(ex.value)
247+
assert ex.match('Consumer closed')
248248

249249
with pytest.raises(RuntimeError) as ex:
250250
c.unsubscribe()
251-
assert 'Consumer closed' == str(ex.value)
251+
assert ex.match('Consumer closed')
252252

253253
with pytest.raises(RuntimeError) as ex:
254254
c.poll()
255-
assert 'Consumer closed' == str(ex.value)
255+
assert ex.match('Consumer closed')
256256

257257
with pytest.raises(RuntimeError) as ex:
258258
c.consume()
259-
assert 'Consumer closed' == str(ex.value)
259+
assert ex.match('Consumer closed')
260260

261261
with pytest.raises(RuntimeError) as ex:
262262
c.assign([TopicPartition('test', 0)])
263-
assert 'Consumer closed' == str(ex.value)
263+
assert ex.match('Consumer closed')
264264

265265
with pytest.raises(RuntimeError) as ex:
266266
c.unassign()
267-
assert 'Consumer closed' == str(ex.value)
267+
assert ex.match('Consumer closed')
268268

269269
with pytest.raises(RuntimeError) as ex:
270270
c.assignment()
271-
assert 'Consumer closed' == str(ex.value)
271+
assert ex.match('Consumer closed')
272272

273273
with pytest.raises(RuntimeError) as ex:
274274
c.commit()
275-
assert 'Consumer closed' == str(ex.value)
275+
assert ex.match('Consumer closed')
276276

277277
with pytest.raises(RuntimeError) as ex:
278278
c.committed([TopicPartition("test", 0)])
279-
assert 'Consumer closed' == str(ex.value)
279+
assert ex.match('Consumer closed')
280280

281281
with pytest.raises(RuntimeError) as ex:
282282
c.position([TopicPartition("test", 0)])
283-
assert 'Consumer closed' == str(ex.value)
283+
assert ex.match('Consumer closed')
284284

285285
with pytest.raises(RuntimeError) as ex:
286286
c.seek([TopicPartition("test", 0, 0)])
287-
assert 'Consumer closed' == str(ex.value)
287+
assert ex.match('Consumer closed')
288288

289289
with pytest.raises(RuntimeError) as ex:
290290
lo, hi = c.get_watermark_offsets(TopicPartition("test", 0))
291-
assert 'Consumer closed' == str(ex.value)
291+
assert ex.match('Consumer closed')
292292

293293

294294
@pytest.mark.skipif(libversion()[1] < 0x000b0000,
@@ -308,16 +308,16 @@ def test_calling_store_offsets_after_close_throws_erro():
308308

309309
with pytest.raises(RuntimeError) as ex:
310310
c.store_offsets(offsets=[TopicPartition("test", 0, 42)])
311-
assert 'Consumer closed' == str(ex.value)
311+
assert ex.match('Consumer closed')
312312

313313
with pytest.raises(RuntimeError) as ex:
314314
c.offsets_for_times([TopicPartition("test", 0)])
315-
assert 'Consumer closed' == str(ex.value)
315+
assert ex.match('Consumer closed')
316316

317317

318318
def test_consumer_withot_groupid():
319319
""" Consumer should raise exception if group.id is not set """
320320

321321
with pytest.raises(ValueError) as ex:
322322
Consumer({'bootstrap.servers': "mybroker:9092"})
323-
assert 'group.id must be set' in str(ex)
323+
assert ex.match('group.id must be set')

tests/test_Producer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ def test_produce_headers_should_fail():
118118
'error_cb': error_cb,
119119
'message.timeout.ms': 10})
120120

121-
with pytest.raises(NotImplementedError) as e:
121+
with pytest.raises(NotImplementedError) as ex:
122122
p.produce('mytopic', value='somedata', key='a key', headers=[('headerkey', 'headervalue')])
123-
assert 'Producer message headers requires confluent-kafka-python built for librdkafka version >=v0.11.4' in str(e)
123+
assert ex.match('Producer message headers requires confluent-kafka-python built for librdkafka version >=v0.11.4')
124124

125125

126126
def test_subclassing():
@@ -188,6 +188,6 @@ def test_set_invalid_partitioner_murmur():
188188
"""
189189
Assert invalid partitioner raises KafkaException
190190
"""
191-
with pytest.raises(KafkaException) as e:
191+
with pytest.raises(KafkaException) as ex:
192192
Producer({'partitioner': 'murmur'})
193-
assert 'Invalid value for configuration property "partitioner": murmur' in str(e)
193+
assert ex.match('Invalid value for configuration property "partitioner": murmur')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy