[TIP] Starting pytest from a microservice framework
nicoddemus at gmail.com
Wed Jan 3 10:54:44 PST 2018
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).
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:
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
When receiving a request to stop the current run, you write a special named
file (".stop" for example), which your hook checks periodically: when it is
found it stops the current execution (probably by raising
Hope this helps!
On Wed, Jan 3, 2018 at 11:06 AM arun kali raja <arunsep886 at gmail.com> wrote:
> I have a requirement where in i want to start pytest from a microservice
> 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.
> i have couple of questions on how to achieve this.
> 1. All pytest invocations i see is from cmd line.. can i invoke the pytest
> run from within another piece of code?
> 2. If yes then can i run it as a seperate thread/process all together from
> the service?
> 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
> Arun Kaliraja.B
> பா. அருண் காளி ராசா
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python