Welcome to pytest-xprocess’s documentation!

A pytest plugin for managing processes. It will make sure external processes on which your application depends are up during every pytest run without the need of manual start-up.


Install plugin via pip:

$ pip install pytest-xprocess

Define your process fixture in conftest.py:

# content of conftest.py

import pytest
from xprocess import ProcessStarter

def myserver(xprocess):
    class Starter(ProcessStarter):
        # startup pattern
        pattern = "PATTERN"

        # command to start process
        args = ['command', 'arg1', 'arg2']

    # ensure process is running and return its logfile
    logfile = xprocess.ensure("myserver", Starter)

    conn = # create a connection or url/port info to the server
    yield conn

    # clean up whole process tree afterwards

Now you can use this fixture in any test functions where myserver needs to be up and xprocess will take care of it for you!