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 <[email protected]> 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 < > [email protected]> 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 >> [email protected] >> https://mail.python.org/mailman/listinfo/pytest-dev >> > > _______________________________________________ > pytest-dev mailing list > [email protected] > https://mail.python.org/mailman/listinfo/pytest-dev > >
_______________________________________________ pytest-dev mailing list [email protected] https://mail.python.org/mailman/listinfo/pytest-dev
