Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
tornadoweb
Tornado
提交
5ae7327e
Tornado
项目概览
镜像
/
tornadoweb
/
Tornado
大约 1 年 前同步成功
通知
26
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Tornado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
5ae7327e
编写于
3月 25, 2018
作者:
B
Ben Darnell
提交者:
GitHub
3月 25, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2327 from bdarnell/test-dont-close
testing: Don't close the event loop if we didn't create it
上级
fb74e481
f47d639f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
51 addition
and
8 deletion
+51
-8
tornado/test/testing_test.py
tornado/test/testing_test.py
+30
-0
tornado/testing.py
tornado/testing.py
+21
-8
未找到文件。
tornado/test/testing_test.py
浏览文件 @
5ae7327e
...
@@ -11,6 +11,11 @@ import platform
...
@@ -11,6 +11,11 @@ import platform
import
traceback
import
traceback
import
warnings
import
warnings
try
:
import
asyncio
except
ImportError
:
asyncio
=
None
@
contextlib
.
contextmanager
@
contextlib
.
contextmanager
def
set_environ
(
name
,
value
):
def
set_environ
(
name
,
value
):
...
@@ -307,5 +312,30 @@ class GenTest(AsyncTestCase):
...
@@ -307,5 +312,30 @@ class GenTest(AsyncTestCase):
self
.
finished
=
True
self
.
finished
=
True
@
unittest
.
skipIf
(
asyncio
is
None
,
"asyncio module not present"
)
class
GetNewIOLoopTest
(
AsyncTestCase
):
def
get_new_ioloop
(
self
):
# Use the current loop instead of creating a new one here.
return
ioloop
.
IOLoop
.
current
()
def
setUp
(
self
):
# This simulates the effect of an asyncio test harness like
# pytest-asyncio.
self
.
orig_loop
=
asyncio
.
get_event_loop
()
self
.
new_loop
=
asyncio
.
new_event_loop
()
asyncio
.
set_event_loop
(
self
.
new_loop
)
super
(
GetNewIOLoopTest
,
self
).
setUp
()
def
tearDown
(
self
):
super
(
GetNewIOLoopTest
,
self
).
tearDown
()
# AsyncTestCase must not affect the existing asyncio loop.
self
.
assertFalse
(
asyncio
.
get_event_loop
().
is_closed
())
asyncio
.
set_event_loop
(
self
.
orig_loop
)
self
.
new_loop
.
close
()
def
test_loop
(
self
):
self
.
assertIs
(
self
.
io_loop
.
asyncio_loop
,
self
.
new_loop
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
tornado/testing.py
浏览文件 @
5ae7327e
...
@@ -74,6 +74,12 @@ else:
...
@@ -74,6 +74,12 @@ else:
import
unittest
# type: ignore
import
unittest
# type: ignore
if
asyncio
is
None
:
_NON_OWNED_IOLOOPS
=
()
else
:
import
tornado.platform.asyncio
_NON_OWNED_IOLOOPS
=
tornado
.
platform
.
asyncio
.
AsyncIOMainLoop
def
bind_unused_port
(
reuse_port
=
False
):
def
bind_unused_port
(
reuse_port
=
False
):
"""Binds a server socket to an available port on localhost.
"""Binds a server socket to an available port on localhost.
...
@@ -216,6 +222,7 @@ class AsyncTestCase(unittest.TestCase):
...
@@ -216,6 +222,7 @@ class AsyncTestCase(unittest.TestCase):
# Clean up Subprocess, so it can be used again with a new ioloop.
# Clean up Subprocess, so it can be used again with a new ioloop.
Subprocess
.
uninitialize
()
Subprocess
.
uninitialize
()
self
.
io_loop
.
clear_current
()
self
.
io_loop
.
clear_current
()
if
not
isinstance
(
self
.
io_loop
,
_NON_OWNED_IOLOOPS
):
# Try to clean up any file descriptors left open in the ioloop.
# Try to clean up any file descriptors left open in the ioloop.
# This avoids leaks, especially when tests are run repeatedly
# This avoids leaks, especially when tests are run repeatedly
# in the same process with autoreload (because curl does not
# in the same process with autoreload (because curl does not
...
@@ -229,9 +236,15 @@ class AsyncTestCase(unittest.TestCase):
...
@@ -229,9 +236,15 @@ class AsyncTestCase(unittest.TestCase):
self
.
__rethrow
()
self
.
__rethrow
()
def
get_new_ioloop
(
self
):
def
get_new_ioloop
(
self
):
"""Creates a new `.IOLoop` for this test. May be overridden in
"""Returns the `.IOLoop` to use for this test.
subclasses for tests that require a specific `.IOLoop` (usually
the singleton `.IOLoop.instance()`).
By default, a new `.IOLoop` is created for each test.
Subclasses may override this method to return
`.IOLoop.current()` if it is not appropriate to use a new
`.IOLoop` in each tests (for example, if there are global
singletons using the default `.IOLoop`) or if a per-test event
loop is being provided by another system (such as
``pytest-asyncio``).
"""
"""
return
IOLoop
()
return
IOLoop
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录