Skip to content

Commit 1dcc85a

Browse files
committed
fix asyncio reactor tests
1 parent fc0803a commit 1dcc85a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tests/unit/io/test_asyncioreactor.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
1-
21
try:
32
from cassandra.io.asyncioreactor import AsyncioConnection
43
import asynctest
54
ASYNCIO_AVAILABLE = True
65
except (ImportError, SyntaxError):
6+
AysncioConnection = None
77
ASYNCIO_AVAILABLE = False
88

9-
from tests import is_monkey_patched
9+
from tests import is_monkey_patched, connection_class
1010
from tests.unit.io.utils import TimerCallback, TimerTestMixin
1111

1212
from mock import patch
1313

1414
import unittest
1515
import time
1616

17+
skip_me = (is_monkey_patched() or
18+
(not ASYNCIO_AVAILABLE) or
19+
(connection_class is not AsyncioConnection))
20+
1721

22+
@unittest.skipIf(is_monkey_patched(), 'runtime is monkey patched for another reactor')
23+
@unittest.skipIf(connection_class is not AsyncioConnection,
24+
'not running asyncio tests; current connection_class is {}'.format(connection_class))
1825
@unittest.skipUnless(ASYNCIO_AVAILABLE, "asyncio is not available for this runtime")
1926
class AsyncioTimerTests(TimerTestMixin, unittest.TestCase):
2027

2128
@classmethod
2229
def setUpClass(cls):
23-
if is_monkey_patched() or not ASYNCIO_AVAILABLE:
30+
if skip_me:
2431
return
2532
cls.connection_class = AsyncioConnection
2633
AsyncioConnection.initialize_reactor()
2734

2835
@classmethod
2936
def tearDownClass(cls):
30-
if ASYNCIO_AVAILABLE:
37+
if skip_me:
38+
return
39+
if ASYNCIO_AVAILABLE and AsyncioConnection._loop:
3140
AsyncioConnection._loop.stop()
3241

3342
@property
@@ -39,6 +48,8 @@ def _timers(self):
3948
raise RuntimeError('no TimerManager for AsyncioConnection')
4049

4150
def setUp(self):
51+
if skip_me:
52+
return
4253
socket_patcher = patch('socket.socket')
4354
self.addCleanup(socket_patcher.stop)
4455
socket_patcher.start()

0 commit comments

Comments
 (0)