Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8425de41
Commit
8425de41
authored
Jun 01, 2018
by
Brett Cannon
Committed by
GitHub
Jun 01, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-33562: Check the global asyncio event loop policy isn't set after any tests (GH-7328)
parent
de651626
Changes
26
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
98 additions
and
2 deletions
+98
-2
Lib/test/libregrtest/save_env.py
Lib/test/libregrtest/save_env.py
+7
-0
Lib/test/support/__init__.py
Lib/test/support/__init__.py
+6
-0
Lib/test/test_asyncgen.py
Lib/test/test_asyncgen.py
+1
-0
Lib/test/test_asyncio/test_base_events.py
Lib/test/test_asyncio/test_base_events.py
+4
-0
Lib/test/test_asyncio/test_buffered_proto.py
Lib/test/test_asyncio/test_buffered_proto.py
+4
-0
Lib/test/test_asyncio/test_context.py
Lib/test/test_asyncio/test_context.py
+4
-0
Lib/test/test_asyncio/test_events.py
Lib/test/test_asyncio/test_events.py
+4
-0
Lib/test/test_asyncio/test_futures.py
Lib/test/test_asyncio/test_futures.py
+4
-0
Lib/test/test_asyncio/test_locks.py
Lib/test/test_asyncio/test_locks.py
+4
-0
Lib/test/test_asyncio/test_pep492.py
Lib/test/test_asyncio/test_pep492.py
+4
-0
Lib/test/test_asyncio/test_proactor_events.py
Lib/test/test_asyncio/test_proactor_events.py
+4
-0
Lib/test/test_asyncio/test_queues.py
Lib/test/test_asyncio/test_queues.py
+4
-0
Lib/test/test_asyncio/test_selector_events.py
Lib/test/test_asyncio/test_selector_events.py
+4
-0
Lib/test/test_asyncio/test_server.py
Lib/test/test_asyncio/test_server.py
+4
-0
Lib/test/test_asyncio/test_sslproto.py
Lib/test/test_asyncio/test_sslproto.py
+4
-0
Lib/test/test_asyncio/test_streams.py
Lib/test/test_asyncio/test_streams.py
+4
-0
Lib/test/test_asyncio/test_subprocess.py
Lib/test/test_asyncio/test_subprocess.py
+5
-0
Lib/test/test_asyncio/test_tasks.py
Lib/test/test_asyncio/test_tasks.py
+4
-0
Lib/test/test_asyncio/test_unix_events.py
Lib/test/test_asyncio/test_unix_events.py
+4
-0
Lib/test/test_asyncio/test_windows_events.py
Lib/test/test_asyncio/test_windows_events.py
+4
-0
Lib/test/test_asyncio/test_windows_utils.py
Lib/test/test_asyncio/test_windows_utils.py
+5
-0
Lib/test/test_contextlib_async.py
Lib/test/test_contextlib_async.py
+2
-1
Lib/test/test_coroutines.py
Lib/test/test_coroutines.py
+1
-1
Lib/test/test_pdb.py
Lib/test/test_pdb.py
+4
-0
Lib/test/test_sys_settrace.py
Lib/test/test_sys_settrace.py
+1
-0
Misc/NEWS.d/next/Tests/2018-06-01-14-25-31.bpo-33562.GutEHf.rst
...EWS.d/next/Tests/2018-06-01-14-25-31.bpo-33562.GutEHf.rst
+2
-0
No files found.
Lib/test/libregrtest/save_env.py
View file @
8425de41
import
asyncio
import
builtins
import
builtins
import
locale
import
locale
import
logging
import
logging
...
@@ -65,8 +66,14 @@ class saved_test_environment:
...
@@ -65,8 +66,14 @@ class saved_test_environment:
'sysconfig._CONFIG_VARS'
,
'sysconfig._INSTALL_SCHEMES'
,
'sysconfig._CONFIG_VARS'
,
'sysconfig._INSTALL_SCHEMES'
,
'files'
,
'locale'
,
'warnings.showwarning'
,
'files'
,
'locale'
,
'warnings.showwarning'
,
'shutil_archive_formats'
,
'shutil_unpack_formats'
,
'shutil_archive_formats'
,
'shutil_unpack_formats'
,
'asyncio.events._event_loop_policy'
,
)
)
def
get_asyncio_events__event_loop_policy
(
self
):
return
support
.
maybe_get_event_loop_policy
()
def
restore_asyncio_events__event_loop_policy
(
self
,
policy
):
asyncio
.
set_event_loop_policy
(
policy
)
def
get_sys_argv
(
self
):
def
get_sys_argv
(
self
):
return
id
(
sys
.
argv
),
sys
.
argv
,
sys
.
argv
[:]
return
id
(
sys
.
argv
),
sys
.
argv
,
sys
.
argv
[:]
def
restore_sys_argv
(
self
,
saved_argv
):
def
restore_sys_argv
(
self
,
saved_argv
):
...
...
Lib/test/support/__init__.py
View file @
8425de41
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
if
__name__
!=
'test.support'
:
if
__name__
!=
'test.support'
:
raise
ImportError
(
'support must be imported from the test package'
)
raise
ImportError
(
'support must be imported from the test package'
)
import
asyncio.events
import
collections.abc
import
collections.abc
import
contextlib
import
contextlib
import
errno
import
errno
...
@@ -2878,3 +2879,8 @@ class FakePath:
...
@@ -2878,3 +2879,8 @@ class FakePath:
raise
self
.
path
raise
self
.
path
else
:
else
:
return
self
.
path
return
self
.
path
def
maybe_get_event_loop_policy
():
"""Return the global event loop policy if one is set, else return None."""
return
asyncio
.
events
.
_event_loop_policy
Lib/test/test_asyncgen.py
View file @
8425de41
...
@@ -328,6 +328,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
...
@@ -328,6 +328,7 @@ class AsyncGenAsyncioTest(unittest.TestCase):
def
tearDown
(
self
):
def
tearDown
(
self
):
self
.
loop
.
close
()
self
.
loop
.
close
()
self
.
loop
=
None
self
.
loop
=
None
asyncio
.
set_event_loop_policy
(
None
)
async
def
to_list
(
self
,
gen
):
async
def
to_list
(
self
,
gen
):
res
=
[]
res
=
[]
...
...
Lib/test/test_asyncio/test_base_events.py
View file @
8425de41
...
@@ -24,6 +24,10 @@ MOCK_ANY = mock.ANY
...
@@ -24,6 +24,10 @@ MOCK_ANY = mock.ANY
PY34
=
sys
.
version_info
>=
(
3
,
4
)
PY34
=
sys
.
version_info
>=
(
3
,
4
)
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
def
mock_socket_module
():
def
mock_socket_module
():
m_socket
=
mock
.
MagicMock
(
spec
=
socket
)
m_socket
=
mock
.
MagicMock
(
spec
=
socket
)
for
name
in
(
for
name
in
(
...
...
Lib/test/test_asyncio/test_buffered_proto.py
View file @
8425de41
...
@@ -4,6 +4,10 @@ import unittest
...
@@ -4,6 +4,10 @@ import unittest
from
test.test_asyncio
import
functional
as
func_tests
from
test.test_asyncio
import
functional
as
func_tests
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
class
ReceiveStuffProto
(
asyncio
.
BufferedProtocol
):
class
ReceiveStuffProto
(
asyncio
.
BufferedProtocol
):
def
__init__
(
self
,
cb
,
con_lost_fut
):
def
__init__
(
self
,
cb
,
con_lost_fut
):
self
.
cb
=
cb
self
.
cb
=
cb
...
...
Lib/test/test_asyncio/test_context.py
View file @
8425de41
...
@@ -3,6 +3,10 @@ import decimal
...
@@ -3,6 +3,10 @@ import decimal
import
unittest
import
unittest
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
class
DecimalContextTest
(
unittest
.
TestCase
):
class
DecimalContextTest
(
unittest
.
TestCase
):
def
test_asyncio_task_decimal_context
(
self
):
def
test_asyncio_task_decimal_context
(
self
):
...
...
Lib/test/test_asyncio/test_events.py
View file @
8425de41
...
@@ -37,6 +37,10 @@ from test.test_asyncio import utils as test_utils
...
@@ -37,6 +37,10 @@ from test.test_asyncio import utils as test_utils
from
test
import
support
from
test
import
support
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
def
osx_tiger
():
def
osx_tiger
():
"""Return True if the platform is Mac OS 10.4 or older."""
"""Return True if the platform is Mac OS 10.4 or older."""
if
sys
.
platform
!=
'darwin'
:
if
sys
.
platform
!=
'darwin'
:
...
...
Lib/test/test_asyncio/test_futures.py
View file @
8425de41
...
@@ -14,6 +14,10 @@ from test.test_asyncio import utils as test_utils
...
@@ -14,6 +14,10 @@ from test.test_asyncio import utils as test_utils
from
test
import
support
from
test
import
support
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
def
_fakefunc
(
f
):
def
_fakefunc
(
f
):
return
f
return
f
...
...
Lib/test/test_asyncio/test_locks.py
View file @
8425de41
...
@@ -16,6 +16,10 @@ STR_RGX_REPR = (
...
@@ -16,6 +16,10 @@ STR_RGX_REPR = (
RGX_REPR = re.compile(STR_RGX_REPR)
RGX_REPR = re.compile(STR_RGX_REPR)
def tearDownModule():
asyncio.set_event_loop_policy(None)
class LockTests(test_utils.TestCase):
class LockTests(test_utils.TestCase):
def setUp(self):
def setUp(self):
...
...
Lib/test/test_asyncio/test_pep492.py
View file @
8425de41
...
@@ -11,6 +11,10 @@ import asyncio
...
@@ -11,6 +11,10 @@ import asyncio
from
test.test_asyncio
import
utils
as
test_utils
from
test.test_asyncio
import
utils
as
test_utils
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
# Test that asyncio.iscoroutine() uses collections.abc.Coroutine
# Test that asyncio.iscoroutine() uses collections.abc.Coroutine
class
FakeCoro
:
class
FakeCoro
:
def
send
(
self
,
value
):
def
send
(
self
,
value
):
...
...
Lib/test/test_asyncio/test_proactor_events.py
View file @
8425de41
...
@@ -16,6 +16,10 @@ from test import support
...
@@ -16,6 +16,10 @@ from test import support
from
test.test_asyncio
import
utils
as
test_utils
from
test.test_asyncio
import
utils
as
test_utils
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
def
close_transport
(
transport
):
def
close_transport
(
transport
):
# Don't call transport.close() because the event loop and the IOCP proactor
# Don't call transport.close() because the event loop and the IOCP proactor
# are mocked
# are mocked
...
...
Lib/test/test_asyncio/test_queues.py
View file @
8425de41
...
@@ -7,6 +7,10 @@ import asyncio
...
@@ -7,6 +7,10 @@ import asyncio
from
test.test_asyncio
import
utils
as
test_utils
from
test.test_asyncio
import
utils
as
test_utils
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
class
_QueueTestBase
(
test_utils
.
TestCase
):
class
_QueueTestBase
(
test_utils
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
Lib/test/test_asyncio/test_selector_events.py
View file @
8425de41
...
@@ -22,6 +22,10 @@ from test.test_asyncio import utils as test_utils
...
@@ -22,6 +22,10 @@ from test.test_asyncio import utils as test_utils
MOCK_ANY
=
mock
.
ANY
MOCK_ANY
=
mock
.
ANY
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
class
TestBaseSelectorEventLoop
(
BaseSelectorEventLoop
):
class
TestBaseSelectorEventLoop
(
BaseSelectorEventLoop
):
def
_make_self_pipe
(
self
):
def
_make_self_pipe
(
self
):
...
...
Lib/test/test_asyncio/test_server.py
View file @
8425de41
...
@@ -9,6 +9,10 @@ from test.test_asyncio import utils as test_utils
...
@@ -9,6 +9,10 @@ from test.test_asyncio import utils as test_utils
from
test.test_asyncio
import
functional
as
func_tests
from
test.test_asyncio
import
functional
as
func_tests
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
class
BaseStartServer
(
func_tests
.
FunctionalTestCaseMixin
):
class
BaseStartServer
(
func_tests
.
FunctionalTestCaseMixin
):
def
new_loop
(
self
):
def
new_loop
(
self
):
...
...
Lib/test/test_asyncio/test_sslproto.py
View file @
8425de41
...
@@ -17,6 +17,10 @@ from test.test_asyncio import utils as test_utils
...
@@ -17,6 +17,10 @@ from test.test_asyncio import utils as test_utils
from
test.test_asyncio
import
functional
as
func_tests
from
test.test_asyncio
import
functional
as
func_tests
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
@
unittest
.
skipIf
(
ssl
is
None
,
'No ssl module'
)
@
unittest
.
skipIf
(
ssl
is
None
,
'No ssl module'
)
class
SslProtoHandshakeTests
(
test_utils
.
TestCase
):
class
SslProtoHandshakeTests
(
test_utils
.
TestCase
):
...
...
Lib/test/test_asyncio/test_streams.py
View file @
8425de41
...
@@ -19,6 +19,10 @@ import asyncio
...
@@ -19,6 +19,10 @@ import asyncio
from
test.test_asyncio
import
utils
as
test_utils
from
test.test_asyncio
import
utils
as
test_utils
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
class
StreamTests
(
test_utils
.
TestCase
):
class
StreamTests
(
test_utils
.
TestCase
):
DATA
=
b'line1
\
n
line2
\
n
line3
\
n
'
DATA
=
b'line1
\
n
line2
\
n
line3
\
n
'
...
...
Lib/test/test_asyncio/test_subprocess.py
View file @
8425de41
...
@@ -23,6 +23,11 @@ PROGRAM_CAT = [
...
@@ -23,6 +23,11 @@ PROGRAM_CAT = [
'data = sys.stdin.buffer.read()'
,
'data = sys.stdin.buffer.read()'
,
'sys.stdout.buffer.write(data)'
))]
'sys.stdout.buffer.write(data)'
))]
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
class
TestSubprocessTransport
(
base_subprocess
.
BaseSubprocessTransport
):
class
TestSubprocessTransport
(
base_subprocess
.
BaseSubprocessTransport
):
def
_start
(
self
,
*
args
,
**
kwargs
):
def
_start
(
self
,
*
args
,
**
kwargs
):
self
.
_proc
=
mock
.
Mock
()
self
.
_proc
=
mock
.
Mock
()
...
...
Lib/test/test_asyncio/test_tasks.py
View file @
8425de41
...
@@ -24,6 +24,10 @@ from test import support
...
@@ -24,6 +24,10 @@ from test import support
from
test.support.script_helper
import
assert_python_ok
from
test.support.script_helper
import
assert_python_ok
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
@
asyncio
.
coroutine
@
asyncio
.
coroutine
def
coroutine_function
():
def
coroutine_function
():
pass
pass
...
...
Lib/test/test_asyncio/test_unix_events.py
View file @
8425de41
...
@@ -31,6 +31,10 @@ from test.test_asyncio import utils as test_utils
...
@@ -31,6 +31,10 @@ from test.test_asyncio import utils as test_utils
MOCK_ANY
=
mock
.
ANY
MOCK_ANY
=
mock
.
ANY
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
def
close_pipe_transport
(
transport
):
def
close_pipe_transport
(
transport
):
# Don't call transport.close() because the event loop and the selector
# Don't call transport.close() because the event loop and the selector
# are mocked
# are mocked
...
...
Lib/test/test_asyncio/test_windows_events.py
View file @
8425de41
...
@@ -15,6 +15,10 @@ from asyncio import windows_events
...
@@ -15,6 +15,10 @@ from asyncio import windows_events
from
test.test_asyncio
import
utils
as
test_utils
from
test.test_asyncio
import
utils
as
test_utils
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
class
UpperProto
(
asyncio
.
Protocol
):
class
UpperProto
(
asyncio
.
Protocol
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
buf
=
[]
self
.
buf
=
[]
...
...
Lib/test/test_asyncio/test_windows_utils.py
View file @
8425de41
...
@@ -10,10 +10,15 @@ if sys.platform != 'win32':
...
@@ -10,10 +10,15 @@ if sys.platform != 'win32':
import
_overlapped
import
_overlapped
import
_winapi
import
_winapi
import
asyncio
from
asyncio
import
windows_utils
from
asyncio
import
windows_utils
from
test
import
support
from
test
import
support
def
tearDownModule
():
asyncio
.
set_event_loop_policy
(
None
)
class
PipeTests
(
unittest
.
TestCase
):
class
PipeTests
(
unittest
.
TestCase
):
def
test_pipe_overlapped
(
self
):
def
test_pipe_overlapped
(
self
):
...
...
Lib/test/test_contextlib_async.py
View file @
8425de41
...
@@ -18,7 +18,7 @@ def _async_test(func):
...
@@ -18,7 +18,7 @@ def _async_test(func):
return
loop
.
run_until_complete
(
coro
)
return
loop
.
run_until_complete
(
coro
)
finally
:
finally
:
loop
.
close
()
loop
.
close
()
asyncio
.
set_event_loop
(
None
)
asyncio
.
set_event_loop
_policy
(
None
)
return
wrapper
return
wrapper
...
@@ -295,6 +295,7 @@ class TestAsyncExitStack(TestBaseExitStack, unittest.TestCase):
...
@@ -295,6 +295,7 @@ class TestAsyncExitStack(TestBaseExitStack, unittest.TestCase):
self
.
loop
=
asyncio
.
new_event_loop
()
self
.
loop
=
asyncio
.
new_event_loop
()
asyncio
.
set_event_loop
(
self
.
loop
)
asyncio
.
set_event_loop
(
self
.
loop
)
self
.
addCleanup
(
self
.
loop
.
close
)
self
.
addCleanup
(
self
.
loop
.
close
)
self
.
addCleanup
(
asyncio
.
set_event_loop_policy
,
None
)
@
_async_test
@
_async_test
async
def
test_async_callback
(
self
):
async
def
test_async_callback
(
self
):
...
...
Lib/test/test_coroutines.py
View file @
8425de41
...
@@ -2142,7 +2142,7 @@ class CoroAsyncIOCompatTest(unittest.TestCase):
...
@@ -2142,7 +2142,7 @@ class CoroAsyncIOCompatTest(unittest.TestCase):
pass
pass
finally
:
finally
:
loop
.
close
()
loop
.
close
()
asyncio
.
set_event_loop
(
None
)
asyncio
.
set_event_loop
_policy
(
None
)
self
.
assertEqual
(
buffer
,
[
1
,
2
,
'MyException'
])
self
.
assertEqual
(
buffer
,
[
1
,
2
,
'MyException'
])
...
...
Lib/test/test_pdb.py
View file @
8425de41
...
@@ -745,6 +745,7 @@ def test_pdb_next_command_for_coroutine():
...
@@ -745,6 +745,7 @@ def test_pdb_next_command_for_coroutine():
... loop = asyncio.new_event_loop()
... loop = asyncio.new_event_loop()
... loop.run_until_complete(test_main())
... loop.run_until_complete(test_main())
... loop.close()
... loop.close()
... asyncio.set_event_loop_policy(None)
... print("finished")
... print("finished")
>>> with PdbTestInput(['step',
>>> with PdbTestInput(['step',
...
@@ -804,6 +805,7 @@ def test_pdb_next_command_for_asyncgen():
...
@@ -804,6 +805,7 @@ def test_pdb_next_command_for_asyncgen():
... loop = asyncio.new_event_loop()
... loop = asyncio.new_event_loop()
... loop.run_until_complete(test_main())
... loop.run_until_complete(test_main())
... loop.close()
... loop.close()
... asyncio.set_event_loop_policy(None)
... print("finished")
... print("finished")
>>> with PdbTestInput(['step',
>>> with PdbTestInput(['step',
...
@@ -915,6 +917,7 @@ def test_pdb_return_command_for_coroutine():
...
@@ -915,6 +917,7 @@ def test_pdb_return_command_for_coroutine():
... loop = asyncio.new_event_loop()
... loop = asyncio.new_event_loop()
... loop.run_until_complete(test_main())
... loop.run_until_complete(test_main())
... loop.close()
... loop.close()
... asyncio.set_event_loop_policy(None)
... print("finished")
... print("finished")
>>> with PdbTestInput(['step',
>>> with PdbTestInput(['step',
...
@@ -1005,6 +1008,7 @@ def test_pdb_until_command_for_coroutine():
...
@@ -1005,6 +1008,7 @@ def test_pdb_until_command_for_coroutine():
... loop = asyncio.new_event_loop()
... loop = asyncio.new_event_loop()
... loop.run_until_complete(test_main())
... loop.run_until_complete(test_main())
... loop.close()
... loop.close()
... asyncio.set_event_loop_policy(None)
... print("finished")
... print("finished")
>>> with PdbTestInput(['step',
>>> with PdbTestInput(['step',
...
...
Lib/test/test_sys_settrace.py
View file @
8425de41
...
@@ -667,6 +667,7 @@ class JumpTestCase(unittest.TestCase):
...
@@ -667,6 +667,7 @@ class JumpTestCase(unittest.TestCase):
with
self
.
assertRaisesRegex
(
*
error
):
with
self
.
assertRaisesRegex
(
*
error
):
asyncio
.
run
(
func
(
output
))
asyncio
.
run
(
func
(
output
))
sys
.
settrace
(
None
)
sys
.
settrace
(
None
)
asyncio
.
set_event_loop_policy
(
None
)
self
.
compare_jump_output
(
expected
,
output
)
self
.
compare_jump_output
(
expected
,
output
)
def
jump_test
(
jumpFrom
,
jumpTo
,
expected
,
error
=
None
,
event
=
'line'
):
def
jump_test
(
jumpFrom
,
jumpTo
,
expected
,
error
=
None
,
event
=
'line'
):
...
...
Misc/NEWS.d/next/Tests/2018-06-01-14-25-31.bpo-33562.GutEHf.rst
0 → 100644
View file @
8425de41
Check that a global asyncio event loop policy is not left behind by any
tests.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment