[pytest-dev] pytest overall execution timeout option

Edison Gustavo Muenz edisongustavo at gmail.com
Mon Apr 18 09:41:28 EDT 2016


Why is the fixture only called at the end? Is this guaranteed behaviour
from pytest?

On Mon, Apr 18, 2016 at 10:26 AM, Bruno Oliveira <nicoddemus at gmail.com>
wrote:

> Hi Shankar,
>
> I don’t know of any plugin that does this out of the box, but the simplest
> way I found is to implement this is using an auto-use fixture:
>
> # contents of conftest.pyimport pytestimport time
> def pytest_sessionstart(session):
>     session.start_time = time.time()
> @pytest.fixture(autouse=True)def check_session_time(request):
>     elapsed = time.time() - request.session.start_time
>     if elapsed > 1.0:
>         request.session.shouldstop = 'time limit reached: %0.2f seconds' % elapsed
> # contents of test_foo.pyimport pytestimport time
> @pytest.mark.parametrize('i', range(10))def test_foo(i):
>     time.sleep(0.5)
>
> Running this produces:
>
> collected 10 items
>
> test_foo.py ...
>
> !!!!!!!!!!!!!!!! Interrupted: time limit reached: 1.11 seconds !!!!!!!!!!!!!!!!
> ========================== 3 passed in 1.69 seconds ===========================
>
> Hope that helps.
>
> Cheers,
> Bruno.
>>
> On Mon, Apr 18, 2016 at 8:56 AM Shankar Hiremath <
> shankarhiremath2006 at gmail.com> wrote:
>
>> Hi All,
>>
>> Is there any any plugin similar to "pytest-timeout” but at higher level
>> (ex: complete suite level execution timeout)
>>
>> My requirement is to run pytest with test suites and if all tests
>> finishes well within the 2 hours time duration then its good, else I want
>> to stop the test execution.
>> ( I mean stop the current running test & further tests if any,  but the
>> pytest call backs should get executed, for example: pytest_sessionfinish
>> need to be executed, before exiting pytest)
>>
>> Please suggest me if any existing plugins provides this feature, or any
>> easy way to achieve this feature in pytest.
>>
>> Thanks
>> -Shankar
>> _______________________________________________
>> pytest-dev mailing list
>> pytest-dev at python.org
>> https://mail.python.org/mailman/listinfo/pytest-dev
>>
>
> _______________________________________________
> pytest-dev mailing list
> pytest-dev at python.org
> https://mail.python.org/mailman/listinfo/pytest-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20160418/1290f7bd/attachment-0001.html>


More information about the pytest-dev mailing list