<p dir="ltr">Hi Arun,</p>
<p dir="ltr">you can control all the above in your implementation of pytest_runtestloop.</p>
<p dir="ltr">Cheers </p>
<br><div class="gmail_quote"><div dir="ltr">Em qui, 4 de jan de 2018 05:39, arun kali raja &lt;<a href="mailto:arunsep886@gmail.com">arunsep886@gmail.com</a>&gt; escreveu:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="auto"><div>Thanks a lot Bruno,<div dir="auto"><br></div><div dir="auto">One more requirement i have is to execute a set of test cases repeatedly in a loop for a particular amount of time.. say 24 hours.. </div><div dir="auto"><br></div><div dir="auto">As per my understanding, in pytest when I do a loop, the different test item objects are created according to the number of the loop at the startup phase itself.. so the tests will be named test1[1/n],test[2/n]...test[n/n].</div><div dir="auto"><br></div><div>Now if i want to run for a particular duration how do i achieve that??</div><div><br></div><div>one way is to have user mark each testcase with the amount of time it will take to complete and then decide how many iterations each of them should be run.. Is there any other way i can achieve it?</div><div><br></div><div>Also i see that the order of execution of testcases is also not maintained.. say i have test_1 run 3 times in a loop.. i see test_1[3/3] run first and then test_1[1/3] is executed.. </div><div><br></div><div>Regards</div><div>Arun Kaliraja.B</div></div></div></div><div dir="ltr"><div dir="auto"><div><div dir="auto"><br></div><div dir="auto"><br></div><br><div class="gmail_extra"><br><div class="gmail_quote">On 04-Jan-2018 00:24, &quot;Bruno Oliveira&quot; &lt;<a href="mailto:nicoddemus@gmail.com" target="_blank">nicoddemus@gmail.com</a>&gt; wrote:<br type="attribution"><blockquote class="m_3765836739888877686m_3116005847346724352quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Arun,<div><br></div><div>You can call pytest.main() directly instead of the command line, but using the command line in a sub-process is also reasonable IMHO (you might want to send a full log of the run back to the client for example).</div><div><br></div><div>In order to stop test mid-execution you will need to implement your own pytest_runtestloop hook in a conftest.py file that will verify some condition between each run:</div><div><br></div><div><a href="https://github.com/pytest-dev/pytest/blob/08997279f40f9c972c116195cc4d83f33ef17b0e/_pytest/main.py#L155" target="_blank">https://github.com/pytest-dev/pytest/blob/08997279f40f9c972c116195cc4d83f33ef17b0e/_pytest/main.py#L155</a><br></div><div><br></div><div>To keep things simple, upon each request for a new test session, create a temporary directory and put your conftest.py file in there along with the tests:</div><div><br></div><div>/tmp/run0/</div><div>  conftest.py</div><div>  test_1.py</div><div>  test_2.py</div><div>  ...</div><div><br></div><div>When receiving a request to stop the current run, you write a special named file (&quot;.stop&quot; for example), which your hook checks periodically: when it is found it stops the current execution (probably by raising session.Interrupted).</div><div><br></div><div>Hope this helps!</div><div><br></div><div>Cheers,</div></div><br><div class="gmail_quote"><div class="m_3765836739888877686m_3116005847346724352elided-text"><div dir="ltr">On Wed, Jan 3, 2018 at 11:06 AM arun kali raja &lt;<a href="mailto:arunsep886@gmail.com" target="_blank">arunsep886@gmail.com</a>&gt; wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_3765836739888877686m_3116005847346724352elided-text"><div dir="ltr">Hi,<div><br></div><div>I have a requirement where in i want to start pytest from a microservice framework.</div><div><br></div><div>So the user will be sending a restAPI request and based on that i should be able to do the service will start a pytest session.</div><div><br></div><div>i have couple of questions on how to achieve this.</div><div><br></div><div>1. All pytest invocations i see is from cmd line.. can i invoke the pytest run from within another piece of code?</div><div><br></div><div>2. If yes then can i run it as a seperate thread/process all together from the service?</div><div><br></div><div>3. If yes to that also.. suppose i want to handle rest requests like stop testrun in between how do i achieve it.. i dont want to kill the thread.. once the ongoing test is completed then i should stop the execution gracefully. python threading library offers event objects to achieve such things.. i am not sure if i will be able to do such things in a conftest.py..</div><div><br></div><div>Regards</div><div>Arun Kaliraja.B </div><div><div><br></div>-- <br><div class="m_3765836739888877686m_3116005847346724352m_7821809358155866780m_1829661503309873029gmail_signature" data-smartmail="gmail_signature">அன்புடன்,<br>
பா. அருண் காளி ராசா </div>
</div></div></div>
_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" rel="noreferrer" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
</blockquote></div>
</blockquote></div><br></div></div></div></div></blockquote></div>