Skip to main content

MongoDB process and client fixtures plugin for py.test.

Project description

pytest-mongo

Latest PyPI version Wheel Status Supported Python Versions License

Package status

Tests Coverage Status Requirements Status

What is this?

This is a pytest plugin, that enables you to test your code that relies on a running MongoDB database. It allows you to specify fixtures for MongoDB process and client.

How to use

Plugin contains two fixtures

  • mongodb - it’s a client fixture that has functional scope, and which cleans MongoDB at the end of each test.

  • mongo_proc - session scoped fixture, that starts MongoDB instance at the first use and stops at the end of the tests.

Simply include one of these fixtures into your tests fixture list.

You can also create additional MongoDB client and process fixtures if you’d need to:

from pytest_mongo import factories

mongo_my_proc = factories.mongo_proc(
    port=None, logsdir='/tmp')
mongo_my = factories.mongodb('mongo_my_proc')

Configuration

You can define your settings in three ways, it’s fixture factory argument, command line option and pytest.ini configuration option. You can pick which you prefer, but remember that these settings are handled in the following order:

  • Fixture factory argument

  • Command line option

  • Configuration option in your pytest.ini file

What

Fixture factory argument

Command line option

pytest.ini option

Default

Path to mongodb exec

executable

–mongo-exec

mongo_exec

/usr/bin/mongod

MongoDB host

host

–mongo-host

mongo_host

127.0.0.1

MongoDB port

port

–mongo-port

mongo_port

random

Path to store logs

logsdir

–mongo-logsdir

mongo_logsdir

$TMPDIR

Additional parameters

params

–mongo-params

mongo_params

Example usage:

  • pass it as an argument in your own fixture

    mongo_proc = factories.mongo_proc(port=8888)
  • use --mongo-port command line option when you run your tests

    py.test tests --mongo-port=8888
  • specify your directory as mongo_port in your pytest.ini file.

    To do so, put a line like the following under the [pytest] section of your pytest.ini:

    [pytest]
    mongo_port = 8888

Package resources

Travis-ci

After creating package on github, move to tracis-ci.org, and turn on ci builds for given package.

CHANGELOG

1.0.0

  • [feature] defaults logs dir to $TMPDIR by default

  • [feature] run on random port by default (easier xdist integration)

  • [feature] add command line and ini option for: executable, host, port, params and logsdir

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

Uploaded Source

Built Distributions

pytest_mongo-1.0.0-py2.py3-none-any.whl (11.0 kB view details)

Uploaded Python 2 Python 3

pytest_mongo-1.0.0-py2.7.egg (13.2 kB view details)

Uploaded Source

File details

Details for the file pytest-mongo-1.0.0.tar.gz.

File metadata

File hashes

Hashes for pytest-mongo-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e527a6fcc60c25bb5eea4bfe92707e81a0c3b5c9066242acb0b0ac4211c733ba
MD5 b8647da9f7186e5b34e67d0ddbaa4b85
BLAKE2b-256 b13f27d8444f791a1394559e67e475ae28d96d7d7051a135664585ac3921fe91

See more details on using hashes here.

File details

Details for the file pytest_mongo-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_mongo-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5bbe32bcebe127c7a2236e62c6a6918b9afc4814a042332ad15e65230dee7adf
MD5 7ec750b476acc6572b7ddb2b4bcb96e4
BLAKE2b-256 91da1958a8480802a9eed805db8dfa2b5d1fb56eb91b1f31a8803f984f50c189

See more details on using hashes here.

File details

Details for the file pytest_mongo-1.0.0-py2.7.egg.

File metadata

File hashes

Hashes for pytest_mongo-1.0.0-py2.7.egg
Algorithm Hash digest
SHA256 710207f109a5391814ed52ec177393d334a76979076f1e3cf45253258f9f82cd
MD5 882c0f0de6285a69d47f6c7f732d61d4
BLAKE2b-256 c1446332cdc0c4ee985ef18308749b2d1c726bef399e46165ecb78d709a5e355

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