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 details)

Uploaded Source

Built Distributions

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

Uploaded Source

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

Uploaded Python 2

File details

Details for the file pytest-devpi-server-1.1.0.tar.gz.

File metadata

File hashes

Hashes for pytest-devpi-server-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c2e9146949e08b5a7dd828169d403a91cf923f95d7d3c0f6be98d3125df65203
MD5 fd481bff2251cf4a60c6429465db3333
BLAKE2b-256 be94a44136b7380bd90a8d3af11e356e59365d66ff47a8c0fcd901d0bf635ff9

See more details on using hashes here.

File details

Details for the file pytest_devpi_server-1.1.0-py2.7.egg.

File metadata

File hashes

Hashes for pytest_devpi_server-1.1.0-py2.7.egg
Algorithm Hash digest
SHA256 acaa9e347964898f73380893adc4f13a714d057eb2db8916e74d6d4ec65e3371
MD5 98e40d46ccb8c651730fe713a15beacd
BLAKE2b-256 4496c3183ba0f71f037475067a4b3e92b382ceaa643637ca80ac306c8c0b527f

See more details on using hashes here.

File details

Details for the file pytest_devpi_server-1.1.0-py2-none-any.whl.

File metadata

File hashes

Hashes for pytest_devpi_server-1.1.0-py2-none-any.whl
Algorithm Hash digest
SHA256 3b58f1172bfd44eb504b729b98bedbc65bab2803990214f00eb7a88ba433ffee
MD5 f8bcc82066b51770e3dc0e652f8c236d
BLAKE2b-256 e6537714497c861fb269e329e44f88481884305de58826900d7d226437d0a602

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