[英]Is it possible to continue executing other tests after pytest-timeout timeouts?
If one of my tests timeouts I receive a timeout message and all other tests are not executed.如果我的其中一个测试超时,我会收到一条超时消息,并且不会执行所有其他测试。 Is there a way to make pytest continue running other tests after that?
有没有办法让pytest在那之后继续运行其他测试?
Edit编辑
Example:例子:
add.py:添加.py:
import time
def add(a, b):
if a == 2:
time.sleep(2)
elif a == 3:
time.sleep(4)
return a + b
test_add.py: test_add.py:
import pytest
from add import add
@pytest.mark.parametrize(
'a, b, expected_result', [
(1, 1, 2),
(2, 2, 4),
(2, 3, 5),
(3, 2, 5),
(4, 1, 5)
]
)
def test_add(a, b, expected_result):
result = add(a, b)
expected_result = a + b
assert result == expected_result
by running通过跑步
(venv) >pytest test_add.py --timeout=3
i get我明白了
============= test session starts ==============
platform win32 -- Python 3.7.7, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: C:\Users\Kosh\PycharmProjects\calcTest
plugins: timeout-1.4.2
timeout: 3.0s
timeout method: thread
timeout func_only: False
collected 5 items
test_add.py ...
++++++++++++++++++++ Timeout ++++++++++++++++++++
~~~~~~~~~~ Stack of MainThread (10588) ~~~~~~~~~~
File "C:\Users\Kosh\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
.....
The 1st, 2nd and 3rd test were executed, 4th test timeouted and the 5th was not executed.执行了第 1、第 2 和第 3 次测试,第 4 次测试超时,第 5 次未执行。 I am looking for a way to run it.
我正在寻找一种方法来运行它。
pytest-timeout
provieds two timeouts methods: signal and thread. pytest-timeout
提供了两种超时方法:信号和线程。
Signal method provides desired functionality, it does not stop entire test suite in case one is failed.信号方法提供了所需的功能,如果一个测试失败,它不会停止整个测试套件。 But Windows does not support the signal method and thus it can only use the thread method.
但是Windows不支持信号方法,因此只能使用线程方法。
As pytest-timeout
readme says:正如
pytest-timeout
自述文件所说:
thread
线
For each test item the
pytest-timeout
plugin starts a timer thread which will terminate the whole process after the specified timeout.对于每个测试项,
pytest-timeout
插件会启动一个计时器线程,该线程将在指定的超时后终止整个过程。
So this is expected behaviour for Windows .所以这是Windows 的预期行为。 And, as far as I know, a satisfactory workaround has not yet been made , other than using Linux :)
而且,据我所知,除了使用 Linux 之外,还没有找到令人满意的解决方法 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.