Skip to content

Commit d343aa5

Browse files
author
bjmb
committed
Acknowledge comments from the review, updated Gevent and Eventlet unit tests
1 parent 6766d77 commit d343aa5

5 files changed

Lines changed: 29 additions & 29 deletions

File tree

appveyor/run_test.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ nosetests -s -v --with-ignore-docstrings --with-xunit --xunit-file=unit_results.
1616
$env:MONKEY_PATCH_LOOP=1
1717
nosetests -s -v --with-ignore-docstrings --with-xunit --xunit-file=unit_results.xml .\tests\unit\io\test_geventreactor.py
1818
nosetests -s -v --with-ignore-docstrings --with-xunit --xunit-file=unit_results.xml .\tests\unit\io\test_eventletreactor.py
19+
Remove-Item $env:MONKEY_PATCH_LOOP
1920

2021
echo "uploading unit results"
2122
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\unit_results.xml))

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def is_monkey_patched():
5959
return is_gevent_monkey_patched() or is_eventlet_monkey_patched()
6060

6161

62-
MONKEY_PATCH_LOOP = bool(os.getenv('MONKEY_PATCH_LOOP', False) == "1")
62+
MONKEY_PATCH_LOOP = bool(os.getenv('MONKEY_PATCH_LOOP', False))
6363

6464
notwindows = unittest.skipUnless(not "Windows" in platform.system(), "This test is not adequate for windows")
6565
notpypy = unittest.skipUnless(not platform.python_implementation() == 'PyPy', "This tests is not suitable for pypy")

tests/unit/io/test_eventletreactor.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,29 @@
1919
import unittest # noqa
2020

2121
from tests.unit.io.utils import TimerConnectionTests
22-
from tests.unit.io.eventlet_utils import restore_saved_module
23-
from tests import notpypy
24-
from tests import notmonkeypatch
22+
from tests import notpypy, MONKEY_PATCH_LOOP, notmonkeypatch
2523

26-
import time
27-
from eventlet import monkey_patch, kill
24+
from eventlet import monkey_patch
2825

2926
try:
3027
from cassandra.io.eventletreactor import EventletConnection
3128
except ImportError:
3229
EventletConnection = None # noqa
3330

34-
@unittest.skipUnless(EventletConnection is not None, "Skpping the eventlet tests because it's not installed")
35-
@notmonkeypatch
3631
# There are some issues with some versions of pypy and eventlet
3732
@notpypy
33+
@unittest.skipIf(EventletConnection is None, "Skpping the eventlet tests because it's not installed")
34+
@notmonkeypatch
3835
class EventletTimerTest(unittest.TestCase, TimerConnectionTests):
39-
40-
def setUp(self):
41-
self.connection_class = EventletConnection
42-
# We only to patch the time module
43-
monkey_patch(time=True)
36+
@classmethod
37+
def setUpClass(cls):
38+
# This is run even though the class is skipped, so we need
39+
# to make sure no monkey patching is happening
40+
if not MONKEY_PATCH_LOOP:
41+
return
42+
monkey_patch()
43+
cls.connection_class = EventletConnection
4444
EventletConnection.initialize_reactor()
4545

46-
def tearDown(self):
47-
kill(EventletConnection._timeout_watcher)
48-
EventletConnection._timers = None
49-
restore_saved_module(time)
46+
# There is no unpatching because there is not a clear way
47+
# of doing it reliably

tests/unit/io/test_geventreactor.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,26 @@
1919

2020

2121
from tests.unit.io.utils import TimerConnectionTests
22-
from tests import notmonkeypatch
22+
from tests import MONKEY_PATCH_LOOP, notmonkeypatch
2323
try:
2424
from cassandra.io.geventreactor import GeventConnection
2525
import gevent.monkey
26-
from tests.unit.io.gevent_utils import restore_saved_module
2726
except ImportError:
2827
GeventConnection = None # noqa
2928

30-
@unittest.skipUnless(GeventConnection is not None, "Skpping the gevent tests because it's not installed")
29+
30+
@unittest.skipIf(GeventConnection is None, "Skpping the gevent tests because it's not installed")
3131
@notmonkeypatch
3232
class GeventTimerTest(unittest.TestCase, TimerConnectionTests):
33-
34-
def setUp(self):
35-
self.connection_class = GeventConnection
36-
#We only to patch the time module
37-
gevent.monkey.patch_time()
33+
@classmethod
34+
def setUpClass(cls):
35+
# This is run even though the class is skipped, so we need
36+
# to make sure no monkey patching is happening
37+
if not MONKEY_PATCH_LOOP:
38+
return
39+
gevent.monkey.patch_all()
40+
cls.connection_class = GeventConnection
3841
GeventConnection.initialize_reactor()
3942

40-
def tearDown(self):
41-
restore_saved_module("time")
42-
GeventConnection._timers = None
43+
# There is no unpatching because there is not a clear way
44+
# of doing it reliably

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ deps = {[base]deps}
1616

1717
setenv = LIBEV_EMBED=0
1818
CARES_EMBED=0
19-
MONKEY_PATCH_LOOP=0
2019
changedir = {envtmpdir}
2120
commands = nosetests --verbosity=2 --no-path-adjustment {toxinidir}/tests/unit/
2221

0 commit comments

Comments
 (0)