Skip to main content

pytest plugin to manage external processes across test runs

Project description

Experimental py.test 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

@pytest.fixture
def myserver(xprocess):
    def preparefunc(cwd):
        return ("PATTERN", [subprocess args])

    logfile = xprocess.ensure("myserver", preparefunc)
    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 preparefunc is a function which gets the current working directory and returns a (PATTERN, args, env) tuple. If the server has not yet been started:

  • the returned args are used to perform a subprocess invocation with environment env (a mapping) and redirect its stdout to a new logfile

  • 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.

  • the logfile is returned pointing to the line right after the match

else, if the server is already running simply the logfile is returned.

To inherit the main test process environment, return None for env, or omit it and return just (PATTERN, args) from the preparefunc.

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.11.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

pytest_xprocess-0.11.1-py2.py3-none-any.whl (7.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for pytest-xprocess-0.11.1.tar.gz
Algorithm Hash digest
SHA256 529d30ddf9f1d3785e55ed088dafa13e8caf6423fa8b4542785a65c114497bad
MD5 24cd096e1a991dbd32f24ccbcbb0ad56
BLAKE2b-256 0b8143bf26deac19d6efe34c4c0853a7e1ca01120b643d86c374accbbddfb7e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_xprocess-0.11.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 73189432715b96c82ee38b62ffbae8a5c75ec6d8f18015c2a7533cf9376f57cb
MD5 17cba223491a391e3170423d4e2cb95e
BLAKE2b-256 d49ae5c8878e00f9ee6de9908c8da27f5a8f1c803856c39db98be9600d364121

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