MongoDB process and client fixtures plugin for py.test.
Project description
pytest-mongo
Package 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
Bug tracker: https://github.com/ClearcodeHQ/pytest-mongo/issues
CHANGELOG
1.1.2
[enhancement] removed path.py depdendency
1.1.1
[enhancements] set executor timeout to 60. By default mirakuru waits indefinitely, which might cause test hangs
1.1.0
[feature] - migrate usage of getfuncargvalue to getfixturevalue. require at least pytest 3.0.0
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-mongo-1.1.2.tar.gz
.
File metadata
- Download URL: pytest-mongo-1.1.2.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 593347f2c2851623bf822bbb1f9cf7119dacfd5bf68e0fd509f4d0ad4fb3cbda |
|
MD5 | 53e98355eeb320e29831dff835dfafe6 |
|
BLAKE2b-256 | 8a363a22c728d73df8e74e5ef9552ace76337ee3576164e45d44a9e43184c5ac |
File details
Details for the file pytest_mongo-1.1.2-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_mongo-1.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8aa1780e13291f6f162a6758dace0d127a5ea024e05e6cc8d2b315953a04121 |
|
MD5 | ae9040b016926e72704bc83baea53492 |
|
BLAKE2b-256 | 328bb7adda1ffa575cf52583f59828b7a13d76060032622ef788da995058e9e4 |