In pytest i can specify timeout for tests using pytest-timeout but it terminates test run instead of failing tests. There existing solution using signal but it works fo Unix systems only. Is it possible to fail function after timeout without using SIGALRM. It's simple to run a using conftest.py, for example add
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_protocol(item, nextitem):
if item.config.option.timeout is not None:
t = Timer(item.config.option.timeout)
try:
t.start()
yield
finally:
t.stop
But how can i fail test using timer in another thread? I thought trying send pytest.fail from this thread to main thread but it seems impossible. Raising exception also affects this new thread but not one with test. Is there any way to do this?
Aucun commentaire:
Enregistrer un commentaire