[pytest-dev] pytest overall execution timeout option

Bruno Oliveira nicoddemus at gmail.com
Wed Apr 20 12:04:44 EDT 2016


On Wed, Apr 20, 2016 at 11:01 AM Shankar Hiremath <
shankarhiremath2006 at gmail.com> wrote:

> As part of “pytest_sessionfinish” we are doing few major activities
> (collecting cluster logs, artifacts, screen shots & videos of testing and
> moving to central location),
> so if kill the pytest based on global timeout then i will lose all the
> important data which is required for analyzing.
>

Oh right, forgot you mentioned that.

Currently pytest-timeout kills the process when a test times out, I guess
it would be possible to change it to call an optional custom function that
you can use to do your cleanup routines before it effectively kills the
process.

import pytest_timeoutfrom mylib import collect_artifacts_videos_and_move_them

pytest_timeout.before_process_kill = collect_artifacts_videos_and_move_them
def pytest_sessionfinish():
    collect_artifacts_videos_and_move_them()

Your clean up routines would have to be resilient enough to be called even
if a test has not finished yet, however.

Another option is to do something similar to what is done in pytest-timeout
in terms of stopping test execution, but instead of killing the process you
have to set some kind of flag/file/whatever which is monitored by the code
under execution. When that flag/file is set, your code will have to
explicitly bail out of whatever it is doing, and then the pytest test
session would finish normally. One way to stop the section is to set the
“shouldstop” attribute as I demonstrated earlier.

Hope that helps,
Bruno.
​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20160420/6ef6d1c5/attachment.html>


More information about the pytest-dev mailing list