{"id":24056,"library":"mock-firestore","title":"mock-firestore","description":"In-memory implementation of Google Cloud Firestore for use in tests. Currently at version 0.11.0. Release cadence is irregular; last update was a while ago but library is stable.","status":"active","version":"0.11.0","language":"python","source_language":"en","source_url":"https://github.com/mdowds/mock-firestore","tags":["firestore","mock","testing","google-cloud"],"install":[{"cmd":"pip install mock-firestore","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for Firestore protocol types and data structures","package":"google-cloud-firestore","optional":false}],"imports":[{"note":"Module name uses underscore, not hyphen.","wrong":"from mockfirestore import MockFirestore","symbol":"MockFirestore","correct":"from mock_firestore import MockFirestore"}],"quickstart":{"code":"from mock_firestore import MockFirestore\n\nfirestore = MockFirestore()\n# Add a document\ndoc_ref = firestore.collection('users').document('user1')\ndoc_ref.set({'name': 'Alice', 'email': 'alice@example.com'})\n# Query\ndocs = firestore.collection('users').where('name', '==', 'Alice').stream()\nfor doc in docs:\n    print(doc.id, doc.to_dict())\n# Output: user1 {'name': 'Alice', 'email': 'alice@example.com'}","lang":"python","description":"Create a MockFirestore instance and use it like the real Firestore client."},"warnings":[{"fix":"Only use for unit tests where exact constraint emulation is not required.","message":"MockFirestore does not enforce real Firestore constraints like unique document IDs within a collection (auto-ID generation) or transactional isolation. Do not assume identical behavior to production Firestore.","severity":"gotcha","affected_versions":"all"},{"fix":"Simply instantiate without arguments: `MockFirestore()`","message":"The `MockFirestore` constructor no longer accepts `project` or `credentials` arguments in recent versions (0.11.0). Previously you could pass a project ID.","severity":"deprecated","affected_versions":">=0.11.0"},{"fix":"Always perform a write before reading a document that may not exist, or use `document_ref.get().exists` to check.","message":"The `collection()` and `document()` methods return references but do not actually create the underlying data until a write operation (like `.set()` or `.add()`) is performed. Methods like `.get()` on a non-existent document will raise an exception (simulating real Firestore).","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use: from mock_firestore import MockFirestore","cause":"Using incorrect import path with hyphen instead of underscore.","error":"ImportError: cannot import name 'MockFirestore' from 'mockfirestore'"},{"fix":"Remove the 'project' argument: MockFirestore()","cause":"Using deprecated constructor argument in newer versions.","error":"TypeError: __init__() got an unexpected keyword argument 'project'"},{"fix":"Ensure you are using from mock_firestore import MockFirestore and not from google.cloud import firestore","cause":"Possibly mocking the wrong class or not importing from the correct module.","error":"AttributeError: 'MockFirestore' object has no attribute 'collection'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}