summaryrefslogtreecommitdiff
path: root/tests/test_pubsub.py
diff options
context:
space:
mode:
authorGreg Ward <greg@gerg.ca>2016-01-21 09:10:12 -0500
committerGreg Ward <greg@gerg.ca>2016-06-12 19:28:43 -0400
commit86ec8d0458e39c795321348f189457c52ebcceca (patch)
tree6280543cc5d1fd4b9fdb24528183f76b06aa92cb /tests/test_pubsub.py
parent3bdf81ab41464d8e918080234912fc8fd86629af (diff)
downloadredis-py-86ec8d0458e39c795321348f189457c52ebcceca.tar.gz
pubsub: improve error reporting if caller forgets to subscribe
This is an easy mistake to make -- at least, I keep making it. It formerly resulted in a confusing crash, "AttributeError: 'NoneType' object has no attribute 'can_read'", from parse_response(). I have had to dig into the redis-py source code more than once to figure out what went wrong. With this patch, it still crashes, but with a clearer error that clarifies what the calling code forgot to do. Fixes issue #716.
Diffstat (limited to 'tests/test_pubsub.py')
-rw-r--r--tests/test_pubsub.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/test_pubsub.py b/tests/test_pubsub.py
index 5486b75..dacac83 100644
--- a/tests/test_pubsub.py
+++ b/tests/test_pubsub.py
@@ -283,6 +283,14 @@ class TestPubSubMessages(object):
assert self.message == make_message('pmessage', channel,
'test message', pattern=pattern)
+ def test_get_message_without_subscribe(self, r):
+ p = r.pubsub()
+ with pytest.raises(RuntimeError) as info:
+ p.get_message()
+ expect = ('connection not set: '
+ 'did you forget to call subscribe() or psubscribe()?')
+ assert expect in info.exconly()
+
class TestPubSubAutoDecoding(object):
"These tests only validate that we get unicode values back"