我安装pytest
和pytest-timeout
,我按照https://pypi.org/project/pytest-timeout/中的pytest-timeout
的说明为每个单元测试设置超时。在
我只希望单元测试在时间用完时失败,然后继续运行其他单元测试。在
请参阅我的单元测试代码:
# 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"
现在的问题是,我在Windows7中运行这段代码,一旦第二次测试时间用完,测试就会停止,第三次单元测试就不运行了。在
我有如下日志:
D:\dev\pytestlog>;pytest
==============测试会话开始===========
平台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项
试验_日志.py. 在
+++++
~~~~~~~~~~~~~主线程堆栈(17636)~~~~~~~~~~~~~~~
文件“c:\python36-32\lib\runpy.py“,第193行,以主模块形式运行 “main”,mod\u规范) 文件“c:\python36-32\lib\runpy.py“,第85行,运行代码 执行(代码,运行全局)
。。。(这里的日志太多)
文件“D:\dev\pytestlog\test_日志.py“,第15行,在测试?2中 时间。睡觉(四)
+++++
D:\dev\pytestlog>
答案是使用
signal
方法,如documentation中所述在pytest出现第一个错误时退出
带鼻子2
-F,fail fast在第一个错误或失败后停止测试运行
^{pr2}$用鼻子测试
检查您的pytest配置,默认值是exit on first error
相关问题 更多 >
编程相关推荐