A pytest plugin for managing processes across test runs.
Project description
pytest plugin for managing processes across test runs.
Usage
install via:
pip install pytest-xprocess
This will provide a xprocess fixture which helps you to ensure that one ore more longer-running processes are present for your tests. You can use it to start and pre-configure test-specific databases (Postgres, Couchdb, …).
Additionally there are two new command line options:
--xkill # terminates all external processes --xshow # shows currently running processes and log files
xprocess fixture usage
You typically define a project-specific fixture which uses the xprocess fixture internally:
# content of conftest.py
import pytest
from xprocess import ProcessStarter
@pytest.fixture
def myserver(xprocess):
class Starter(ProcessStarter):
pattern = "PATTERN"
args = ['command', 'arg1', 'arg2']
logfile = xprocess.ensure("myserver", Starter)
conn = # create a connection or url/port info to the server
return conn
The xprocess.ensure function takes a name for the external process because you can have multiple external processes.
The Starter is a subclass that gets initialized with the working directory created for this process. If the server has not yet been started:
the args are used to invoke a new subprocess.
the pattern is waited for in the logfile before returning. It should thus match a state of your server where it is ready to answer queries.
env may be defined to customize the environment in which the new subprocess is invoked. To inherit the main test process environment, leave env set to the default (None).
stdout is redirected to a logfile, which is returned pointing to the line right after the match
else, if the server is already running simply the logfile is returned.
To customize the startup behavior, override other methods of the ProcessStarter. For example, to extend the number of lines searched for the startup info:
class Starter(ProcessStarter):
pattern = 'process started at .*'
args = ['command', 'arg1']
def filter_lines(self, lines):
return itertools.islice(lines, 500)
To override the wait behavior, override ProcessStarter.wait. See the xprocess.ProcessStarter interface for more details.
Note that the plugin needs to persist the process ID and logfile information. It does this in a sub directory of the directory which contains a pytest.ini or setup.py file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-xprocess-0.14.0.tar.gz
.
File metadata
- Download URL: pytest-xprocess-0.14.0.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab32cbda38e675e1736c6a7d58e8f8620df4cc9302f63b9a16b4b5744091e119 |
|
MD5 | e9557702d10022fd39fd9d5bee56bc80 |
|
BLAKE2b-256 | aad8ff2647201716d56f592a05184266c83ef5254a3798ae869f7b6aa2187eae |
File details
Details for the file pytest_xprocess-0.14.0-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_xprocess-0.14.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47f0dce9069864aff1991a8ebc89079f6fb9e437e00ad5b3f217448f4fd8470c |
|
MD5 | b7f7d64ebf8ea4eb43902980875c43c0 |
|
BLAKE2b-256 | 97d6482ef5bb5ee00185e13d15fa0a7c8dedb1bdcdda73215e2b21b086c81d55 |