Hi Bruno, Thanks for the suggestion for “pytest_timeout.before_process_kill” but the pytest_timeout works at test case level, what i require is a global timeout for pytest (not at test case level timeout)
Thanks -Shankar On Apr 20, 2016, at 9:34 PM, Bruno Oliveira <[email protected]> wrote: > On Wed, Apr 20, 2016 at 11:01 AM Shankar Hiremath > <[email protected]> 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_timeout > from 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. >
_______________________________________________ pytest-dev mailing list [email protected] https://mail.python.org/mailman/listinfo/pytest-dev
