Skip to content

Commit c5eb7bf

Browse files
hrchuRyan P
authored andcommitted
Fix test case exception handling
Let tests fail if the expected exception not thrown.
1 parent d5642e3 commit c5eb7bf

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

tests/test_Consumer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ def test_basic_api():
1010
""" Basic API tests, these wont really do anything since there is no
1111
broker configured. """
1212

13-
try:
13+
with pytest.raises(TypeError) as ex:
1414
kc = Consumer()
15-
except TypeError as e:
16-
assert str(e) == "expected configuration dict"
15+
assert ex.match('expected configuration dict')
1716

1817
def dummy_commit_cb(err, partitions):
1918
pass

tests/test_Producer.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ def test_basic_api():
1414
""" Basic API tests, these wont really do anything since there is no
1515
broker configured. """
1616

17-
try:
17+
with pytest.raises(TypeError) as ex:
1818
p = Producer()
19-
except TypeError as e:
20-
assert str(e) == "expected configuration dict"
19+
assert ex.match('expected configuration dict')
2120

2221
p = Producer({'socket.timeout.ms': 10,
2322
'error_cb': error_cb,
@@ -136,10 +135,8 @@ def produce_hi(self):
136135
assert type(sp) == SubProducer
137136

138137
# Invalid config should fail
139-
try:
138+
with pytest.raises(KafkaException):
140139
sp = SubProducer({'should.fail': False}, 'mytopic')
141-
except KafkaException:
142-
pass
143140

144141
sp = SubProducer({'log.thread.name': True}, 'mytopic')
145142
sp.produce('someother', value='not hello')

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