{"id":24232,"library":"pgmock","title":"pgmock","description":"A library for mocking Postgres queries in Python tests. Current version 1.3.7, stable release cadence.","status":"active","version":"1.3.7","language":"python","source_language":"en","source_url":"https://github.com/CloverHealth/pgmock","tags":["testing","postgres","mock","database"],"install":[{"cmd":"pip install pgmock","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"Correct import path.","symbol":"MockPGClient","correct":"from pgmock import MockPGClient"},{"note":"Correct exception import.","symbol":"MockDBNotConnectedError","correct":"from pgmock import MockDBNotConnectedError"},{"note":"Base exception class.","symbol":"MockError","correct":"from pgmock import MockError"}],"quickstart":{"code":"from pgmock import MockPGClient\n\nclient = MockPGClient()\n# Simulate a query result\nclient.add_query(\"SELECT 1\", result=[(\"1\",)])\nresult = client.execute(\"SELECT 1\")\nprint(result.fetchall())  # [('1',)]","lang":"python","description":"Initialize MockPGClient, add expected queries, and execute."},"warnings":[{"fix":"Always register expected queries with add_query() or use autospec feature if available.","message":"MockPGClient.execute() requires queries to be added with add_query() before execution, otherwise raises MockDBNotConnectedError","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use from pgmock import MockPGClient instead.","message":"The old import from pgmock import PGMock has been deprecated and will be removed.","severity":"deprecated","affected_versions":">=1.3.0"},{"fix":"Use .fetchall(), .fetchone() or .fetchmany() methods on the returned result.","message":"In version 1.3.0, the .execute() method now returns a ResultProxy instead of a list. Old code expecting list will break.","severity":"breaking","affected_versions":">=1.3.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure you instantiate MockPGClient and add queries before calling execute().","cause":"Trying to use execute() before adding any query or without calling connect() if using context manager.","error":"pgmock.exceptions.MockDBNotConnectedError: No connection established. Please create a MockPGClient instance first."},{"fix":"Run 'pip install pgmock' in the correct Python environment.","cause":"pgmock is not installed or installed in a different environment.","error":"ModuleNotFoundError: No module named 'pgmock'"},{"fix":"Use add_query() method to register queries, e.g., client.add_query('SELECT * FROM table', result=[(1,)]).","cause":"Trying to assign to client['table'] or similar dict-like usage instead of using add_query().","error":"TypeError: 'MockPGClient' object does not support item assignment"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}