Skip to content

Commit 698bdfa

Browse files
authored
fix test_indexing_deprecation pre-3.0 (apache#930)
1 parent 6d6433e commit 698bdfa

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

tests/unit/test_resultset.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
except ImportError:
1919
import unittest # noqa
2020

21-
from mock import Mock, PropertyMock
21+
from mock import Mock, PropertyMock, patch
2222

2323
from cassandra.cluster import ResultSet
2424

@@ -195,19 +195,15 @@ def test_one(self):
195195

196196
self.assertEqual(rs.one(), first)
197197

198-
def test_indexing_deprecation(self):
199-
import warnings
200-
198+
@patch('cassandra.cluster.warn')
199+
def test_indexing_deprecation(self, mocked_warn):
200+
# normally we'd use catch_warnings to test this, but that doesn't work
201+
# pre-Py3.0 for some reason
201202
first, second = Mock(), Mock()
202203
rs = ResultSet(Mock(has_more_pages=False), [first, second])
203204
self.assertEqual(rs[0], first)
204-
205-
with warnings.catch_warnings(record=True) as ws:
206-
# catch_warnings restores original filter on close
207-
warnings.simplefilter('always')
208-
rs[0]
209-
self.assertEqual(len(ws), 1)
210-
index_warning = ws[0]
211-
self.assertIs(index_warning.category, DeprecationWarning)
205+
self.assertEqual(len(mocked_warn.mock_calls), 1)
206+
index_warning_args = tuple(mocked_warn.mock_calls[0])[1]
212207
self.assertIn('indexing support will be removed in 4.0',
213-
str(index_warning.message))
208+
str(index_warning_args[0]))
209+
self.assertIs(index_warning_args[1], DeprecationWarning)

0 commit comments

Comments
 (0)