简体   繁体   中英

How to pause py.test test and do some other tests at the time of waiting?

I have a lot of 'long tests' where I have to wait for some relatively big timeout (minutes). For example I call some API in the test, wait for 15 minutes, and after that check web-page for changes.

So the question is - how to pause some test but do other tests at the time of waiting. I cannot use just sleep() - full test suit in this case will lasts for hours (15 minutes * (number of such tests)).

The one solution that I see - arrange tests (with hook pytest_collection_modifyitems):

  1. Run first parts (before 15 minutes pause) of all long tests (call API in the long test example above)
  2. Run all short tests
  3. (Optional) wait a little if (2) took less than 15 minutes
  4. Run second parts (after pause) of all long tests (check web-page in the example above)

But that would be just a big mess, very hard to manage.

And that produces a lot of dummy tests that run in (1) - in fact this is something like test setups, I do not need results from them, but pytest would treat them as separate tests all the same.

UPD xdist does not help much - even if I can control how it parallelize tests (in which groups that run simultaniously), I would have to run all long tests in parallel, because I want to do something useful in the time of waiting, not just wait (15 minutes * (number of long tests)) / (number of xdist processes).

It seems the only way - to patch main loop of pytest for that. So it will run tests asyncronously. But I do not know even where to start doing that..

UPD2 On the second thought xdist could help If I have enough parallel processess so long running tests won't block small tests during long wait inside this tests..

There is a pytest-xdist plugin for pytest that enables test run parallelization. That is to say, your tests will be run simultaneously by multiple processes (on multiple CPUs) at the same time. That doesn't exactly get at what you're asking -- it doesn't pause long-running tests -- but it does allow other tests to run at the same time that long-running tests are running.

If you can edit your question to describe what you mean by "first parts" and "second parts" of tests, I might be able to give a better answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM