{"id":21806,"library":"pytest-mongo","title":"pytest-mongo","description":"MongoDB process and client fixtures plugin for Pytest. Provides fixtures to start a MongoDB process and provide a pymongo client. Version 4.0.0 requires Python >=3.10 and uses the pytest-dbfixtures framework for managing MongoDB processes.","status":"active","version":"4.0.0","language":"python","source_language":"en","source_url":"https://github.com/dbfixtures/pytest-mongo","tags":["pytest","fixtures","mongo","mongodb","testing","plugin"],"install":[{"cmd":"pip install pytest-mongo","lang":"bash","label":"PyPI install"}],"dependencies":[{"reason":"Core dependency providing MongoDB process management.","package":"pytest-dbfixtures","optional":false},{"reason":"Client fixture uses pymongo.MongoClient.","package":"pymongo","optional":false}],"imports":[{"note":"Old import path (pre v3) no longer works.","wrong":"from pytest_mongo.factory import mongo_proc","symbol":"mongo_proc","correct":"from pytest_mongo import mongo_proc"},{"note":"Fixtures are top-level; no need to import internal classes.","wrong":"from pytest_mongo.executor import MongoClient","symbol":"mongo_client","correct":"from pytest_mongo import mongo_client"}],"quickstart":{"code":"import pytest\n\npytest_plugins = [\"pytest_mongo\"]\n\ndef test_mongo(mongo_client):\n    db = mongo_client.test_database\n    collection = db.test_collection\n    collection.insert_one({\"name\": \"test\"})\n    assert collection.find_one({\"name\": \"test\"}) is not None\n","lang":"python","description":"Add pytest_plugins to conftest or test file, then use mongo_client fixture directly."},"warnings":[{"fix":"Upgrade Python to 3.10+ and adjust conftest.py fixture scopes if relying on session-scoped defaults.","message":"pytest-mongo 4.0.0 drops support for Python <3.10 and may change fixture scopes. Ensure Python >=3.10 and review fixture scope parameters.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Set the MONGODB_BINARY environment variable to an existing mongod binary to skip download. Or use a pre-installed MongoDB in CI.","message":"The mongo_proc fixture starts a real MongoDB process. It downloads mongod if not found, which can be slow and may fail on restricted CI environments.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace pytest-mongo-dbfixtures with pytest-mongo and use mongo_proc and mongo_client.","message":"Direct use of 'mongo_process' or 'mongod' fixtures from old pytest-mongo-dbfixtures is deprecated. Use mongo_proc and mongo_client from pytest_mongo.","severity":"deprecated","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install with 'pip install pytest-mongo' and verify by 'python -c \"import pytest_mongo\"'.","cause":"pytest-mongo installed but not imported correctly or missing in test environment.","error":"ModuleNotFoundError: No module named 'pytest_mongo'"},{"fix":"Add 'pytest_plugins = [\"pytest_mongo\"]' to conftest.py or test file.","cause":"pytest_plugins not set or pytest-mongo plugin not loaded.","error":"pytest fixture 'mongo_client' not found"},{"fix":"Set MONGODB_BINARY env var to full path of mongod, e.g., 'mongod' if in PATH, or install MongoDB.","cause":"MongoDB binary not found; plugin tries to download but may fail.","error":"pytest_mongo.executor.MongoExecutorException: Process failed to start: 'mongod' not found"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}