A mongo mocking library with an ephemeral MongoDB running in memory.
Project description
pymongo_inmemory
A mongo mocking library with an ephemeral MongoDB running in memory.
Installation
pip install pymongo-inmemory
Configuration
Config param | Description | Optional? | Default |
---|---|---|---|
mongo_version | Which MongoD version to download and use. | Yes | 4.0.10 |
mongod_port | Override port preference. | Yes | Automatically determined between 27017 and 28000 |
operating_system | This makes sense for Linux setting, where there are several flavours | Yes | Automatically determined (Generic for Linux) |
Usage
Configure
There are several ways you can configure pymongo_inmemory
.
- Insert a new section to your project's
setup.cfg
for the operating system and mongo version you want to spin up:[pymongo_inmemory] mongo_version = 4.0.10 mongod_port = 27019
- Define an ALL_CAPS environment variable with prefix
PYMONGOIM__
(attention to trailing double underscores.) For instance, to override the port, set up an environment variablePYMONGOIM__MONGOD_PORT
.
Import and use
pymongo_inmemory
wraps the client that comes from pymongo
and configures and ephemeral server.
Then you can import MongoClient
from pymongo_inmemory
instead of pymongo
and use it:
from pymongo_inmemory import MongoClient
client = MongoClient() # No need to provide host
db = client['testdb']
collection = db['test-collection']
# etc., etc.
client.close()
# Also usable with context manager
with MongoClient() as client:
# do stuff
Supported Python versions
Since pytest
uses LocalPath
for path related
operations and on python versions older than 3.6 LocalPath
does not behave well with all path
related operations, we are setting Python 3.6.10 in our development.
Technically, this also limits the minimum Python version of tested features. However theer shouldn't be a hard limitation to use Python 3.5. We recommend upgrading older Python versions than that.
Development
Project is set up to develop with poetry. We rely on pyenv to maintain the minimum supported Python version.
After installing pyenv
, poetry
, and cloning the repo, create the shell and install
all package requirements:
pyenv install --skip-existing
poetry install --no-root
poetry shell
Run the tests:
pytest
If on NIX systems you can run further tests:
bash tests/integrity/test_integrity.sh
See how you can wet your feet, check out good first issues.
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
Hashes for pymongo_inmemory-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 519ad80395663bc6cbd15c443f36d76424dddc10318f7d24b008e1f6c6bfef91 |
|
MD5 | 0a4c4f3f2575b3385d6513d834a08c87 |
|
BLAKE2b-256 | de3a66432931830fec1e9e7259ddf027c384f1d782a8b665c9bdc0fc0fd76bc2 |