[英]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.例如我在测试中调用了一些 API,等待 15 分钟,然后检查网页是否有变化。
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)).我不能只使用 sleep() - 在这种情况下,完整的测试服将持续数小时(15 分钟 *(此类测试的数量))。
The one solution that I see - arrange tests (with hook pytest_collection_modifyitems):我看到的一个解决方案 - 安排测试(使用钩子 pytest_collection_modifyitems):
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.这会产生很多在 (1) 中运行的虚拟测试 - 实际上这类似于测试设置,我不需要它们的结果,但 pytest 会将它们视为单独的测试。
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). UPD xdist 没有太大帮助 - 即使我可以控制它如何并行化测试(在哪些组中同时运行),我也必须并行运行所有长测试,因为我想在等待的时候做一些有用的事情,而不是只需等待(15 分钟 *(长时间测试的数量))/(xdist 进程的数量)。
It seems the only way - to patch main loop of pytest for that.这似乎是唯一的方法 - 为此修补 pytest 的主循环。 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.. UPD2 第二个想法 xdist 可能会有所帮助 如果我有足够的并行进程,那么长时间运行的测试不会在此测试中的长时间等待期间阻塞小测试。
There is a pytest-xdist
plugin for pytest that enables test run parallelization. pytest-xdist
有一个pytest-xdist
插件,可以启用测试运行并行化。 That is to say, your tests will be run simultaneously by multiple processes (on multiple CPUs) at the same time.也就是说,您的测试将由多个进程(在多个 CPU 上)同时运行。 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.如果您可以编辑问题以描述测试的“第一部分”和“第二部分”的含义,我可能会给出更好的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.