I install pytest
and pytest-timeout
, I follow the instrunction of pytest-timeout
in https://pypi.org/project/pytest-timeout/ to set timeout for each unit test.
And I want to only fail the unit test if it run out of time, and continue to run the other unit tests.
Please see my unit tests 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"
Now the problem is, I run this code in my Windows 7, the test will stop once the second time run out of time, the 3rd unit test is not run.
I have the log like following:
D:\dev\pytestlog>pytest
================== test session starts ==============
platform win32 -- Python 3.6.4, pytest-3.8.2, py-1.5.3, pluggy-0.7.1 rootdir: D:\dev\pytestlog, inifile: plugins: timeout-1.3.2, instafail-0.4.0 collected 3 items
test_log.py .
++++++++++++++++++++++++ Timeout ++++++++++++++++++++++++
~~~~~~~~~~~~~~ Stack of MainThread (17636) ~~~~~~~~~~~~~~
File "c:\python36-32\lib\runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "c:\python36-32\lib\runpy.py", line 85, in _run_code exec(code, run_globals)
... (too many logs here)
File "D:\dev\pytestlog\test_log.py", line 15, in test_02 time.sleep(4)
++++++++++++++++++++++++ Timeout ++++++++++++++++++++++++
D:\dev\pytestlog>
@pytest.mark.timeout
can mark individual tests as having a timeout – Reed_Xia