Python中文
首页
教程
问答
标签
搜索
登录
注册
为什么pytest在一次单元测试中退出(@pytest.mark.timeout(3) )超时?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我安装<code>pytest</code>和<code>pytest-timeout</code>,我按照<a href="https://pypi.org/project/pytest-timeout/" rel="nofollow noreferrer">https://pypi.org/project/pytest-timeout/</a>中的<code>pytest-timeout</code>的说明为每个单元测试设置超时。在</p> <p>我只希望单元测试在时间用完时失败,然后继续运行其他单元测试。在</p> <p>请参阅我的单元测试代码:</p> <pre><code># content of test_log.py import time import pytest class TestDemo(object): @pytest.mark.timeout(60) def test_01(self): time.sleep(2) assert "1" @pytest.mark.timeout(3) def test_02(self): time.sleep(4) assert "1" @pytest.mark.timeout(3) def test_03(self): time.sleep(1) assert "1" </code></pre> <p>现在的问题是,我在Windows7中运行这段代码,一旦第二次测试时间用完,测试就会停止,第三次单元测试就不运行了。在</p> <p>我有如下日志:</p> <p>D:\dev\pytestlog>;pytest</p> <p>==============测试会话开始===========</p> <p>平台win32--Python3.6.4、pytest-3.8.2、py-1.5.3、pluggy-0.7.1 根目录:D:\dev\pytestlog,ini文件: 插件:timeout-1.3.2,instafail-0.4.0 收集3项</p> <p>试验_日志.py. 在</p> <p>+++++</p> <p>~~~~~~~~~~~~~主线程堆栈(17636)~~~~~~~~~~~~~~~</p> <p>文件“c:\python36-32\lib\runpy.py“,第193行,以主模块形式运行 “<strong>main</strong>”,mod\u规范) 文件“c:\python36-32\lib\runpy.py“,第85行,运行代码 执行(代码,运行全局)</p> <p>。。。(这里的日志太多)</p> <p>文件“D:\dev\pytestlog\test_日志.py“,第15行,在测试?2中 时间。睡觉(四)</p> <p>+++++</p> <p>D:\dev\pytestlog></p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>答案是使用<code>signal</code>方法,如<a href="https://pypi.org/project/pytest-timeout/" rel="nofollow noreferrer">documentation</a>中所述</p> <pre><code>@pytest.mark.timeout(5, method='signal') def test_foo(): pass </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何添加虚拟方法
6 回答
如何添加表示整数的擦边字符串?
8 回答
如何添加要在Bokeh中使用的新font.ttf文件?
8 回答
如何添加要显示的矩阵XY轴编号和XY轴
8 回答
如何添加计数?
7 回答
如何添加计数器函数?
4 回答
如何添加计数器列来计算数据帧中另一列中的特定值?
3 回答
如何添加计数器来跟踪while循环中的月份和年份?
3 回答
如何添加计数并删除countplot的顶部和右侧脊椎?
2 回答
如何添加计时器wx.应用程序更新窗口对象的主循环?
8 回答
如何添加评论到帖子?PostDetailVew,Django 2.1.5
4 回答
如何添加评论拉梅尔亚姆
8 回答
如何添加诸如矩阵Python/Pandas之类的数据帧?
1 回答
如何添加谷歌地点自动完成到Flask?
3 回答
如何添加超时、python discord bot
1 回答
如何添加超过1dp的检查
1 回答
如何添加距离方法
10 回答
如何添加跟随游戏的敌人精灵
6 回答
如何添加路径以便python可以找到程序?
5 回答
如何添加身份验证/安全性以使用happybase访问HBase?
9 回答