Skip to main content

DevPI server fixture for py.test

Project description

DevPi server fixture for py.test. The server is session-scoped by default and run in a subprocess and temp dir to cleanup when it’s done.

After the server has started up it will create a single user with a password, and an index for that user. It then activates that index and provides a handle to the devpi-client API so you can manipulate the server in your tests.

Installation

Install using your favourite package manager:

pip install pytest-devpi-server
#  or..
easy_install pytest-devpi-server

Enable the fixture explicitly in your tests or conftest.py (not required when using setuptools entry points):

pytest_plugins = ['pytest_devpi_server']

Example

Here’s a noddy test case showing the main functionality:

def test_devpi_server(devpi_server):
    # This is the client API for the server that's bound directly to the 'devpi' command-line tool.
    # Here we list the available indexes
    print devpi_server.api('use', '-l')

    # Create and use another index
    devpi_server.api('index', '-c', 'myindex')
    devpi_server.api('index', 'use', 'myindex')

    # Upload a package
    import os
    os.chdir('/path/to/my/setup/dot/py')
    devpi_server.api('upload')

    # Get some json data
    import json
    res = devpi_server.api('getjson', '/user/myindex')
    assert json.loads(res)['result']['projects'] == ['my-package-name']

DevpiServer class

Using this with the default devpi_server py.test fixture is good enough for a lot of use-cases however you may wish to have more fine-grained control about the server configuration.

To do this you can use the underlying server class directly - this is an implenentation of the pytest-server-fixture framework and as such acts as a context manager:

import json
from pytest_devpi_server import DevpiServer

def test_custom_server():
    with DevPiServer(
          # You can specify you own initial user and index
          user='bob',
          password='secret',
          index='myindex',

          # You can provide a zip file that contains the initial server database,
          # this is useful to pre-load any required packages for a test run
          data='/path/to/data.zip'
       ) as server:

           assert not server.dead
           res = server.api('getjson', '/bob/myindex')
           assert 'pre-loaded-package' in json.loads(res)['result']['projects']

    # Server should now be dead
    assert server.dead

Changelog

1.1.0 (2016-2-15)

  • New plugin: devpi server fixture

  • pytest-profiling improvement: overly-long .prof files are saved as the short hash of the test name (Thanks to Vladimir Lagunov for PR)

  • Changed default behavior of workspace.run() to not use a subshell for security reasons

  • Corrected virtualenv.run() method to handle arguments the same as the parent method workspace.run()

  • Removed deprecated ‘–distribute’ from virtualenv args

1.0.1 (2015-12-23)

  • Packaging bugfix

1.0.0 (2015-12-21)

  • Initial public release

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-devpi-server-1.1.0.tar.gz (5.9 kB view hashes)

Uploaded Source

Built Distributions

pytest_devpi_server-1.1.0-py2.7.egg (4.7 kB view hashes)

Uploaded Source

pytest_devpi_server-1.1.0-py2-none-any.whl (7.3 kB view hashes)

Uploaded Python 2

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