Skip to main content

pytest plugin to manage external processes across test runs

Project description

Experimental `py.test <https://pytest.org>`_ 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 pytest_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 :method:`ProcessStarter.wait`.
See the :class:`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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-xprocess-0.12.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

pytest_xprocess-0.12-py2.py3-none-any.whl (8.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest-xprocess-0.12.tar.gz.

File metadata

File hashes

Hashes for pytest-xprocess-0.12.tar.gz
Algorithm Hash digest
SHA256 736d7286e1b84fc0db623a8b5e6c2639331d6e7b5a4a4b7ba85dcbf37492ca20
MD5 971f490a780844865bd1aec1b34b3c76
BLAKE2b-256 312da007a78b190da71671766e61d4c07f85e96ea27d7ea23da2326a1b933b7f

See more details on using hashes here.

File details

Details for the file pytest_xprocess-0.12-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_xprocess-0.12-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f5565076d0da49a77fdd64b847cbee06187f6caa959255b574e24ef401f83784
MD5 90842c9bff4fbe76fe87d10d6fd44e5e
BLAKE2b-256 6c195f7a63597b791422720b8fc089687c4327883194aac9b11174e7244421e2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page