[英]Is it possible to continue executing other tests after pytest-timeout timeouts?
如果我的其中一個測試超時,我會收到一條超時消息,並且不會執行所有其他測試。 有沒有辦法讓pytest在那之后繼續運行其他測試?
編輯
例子:
添加.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:
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
通過跑步
(venv) >pytest test_add.py --timeout=3
我明白了
============= 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)
.....
執行了第 1、第 2 和第 3 次測試,第 4 次測試超時,第 5 次未執行。 我正在尋找一種方法來運行它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.