Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add disable_get_running_loop method to TestCase
  • Loading branch information
vinmic
vinmic committed Jun 3, 2016
commit 121cca3fef3820a1850df91f6d772e40ed5844d4
16 changes: 16 additions & 0 deletions asyncio/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,25 @@ def get_function_source(func):


class TestCase(unittest.TestCase):
def disable_get_event_loop(self):
policy = events.get_event_loop_policy()
if hasattr(policy, '_patched_get_event_loop'):
return

def reset_event_loop_method():
policy.get_running_loop = old_get_running_loop
del policy._patched_get_event_loop

old_get_running_loop = policy.get_running_loop
policy.get_running_loop = lambda: None
policy._patched_get_event_loop = True

self.addCleanup(reset_event_loop_method)

def set_event_loop(self, loop, *, cleanup=True):
assert loop is not None
# ensure that the event loop is passed explicitly in asyncio
self.disable_get_event_loop()
events.set_event_loop(None)
if cleanup:
self.addCleanup(loop.close)
Expand Down