{"id":24699,"library":"testgres","title":"testgres","description":"testgres is a testing utility for PostgreSQL and its extensions, providing a simple API to manage temporary PostgreSQL instances, create databases, execute queries, and test replication. Current version 1.13.7, PyPI release with monthly cadence.","status":"active","version":"1.13.7","language":"python","source_language":"en","source_url":"https://github.com/postgres-ai/testgres","tags":["postgresql","testing","temporary-database","integration-test","replication"],"install":[{"cmd":"pip install testgres","lang":"bash","label":"Install testgres"}],"dependencies":[],"imports":[{"note":"Direct import of the module; no submodule import needed.","wrong":"","symbol":"testgres","correct":"import testgres"}],"quickstart":{"code":"import testgres\n\ndef test_postgres():\n    # Start a temporary PostgreSQL instance\n    with testgres.get_new_node('test_node') as node:\n        node.init()\n        node.start()\n        # Create a database and execute a query\n        db = node.execute('CREATE DATABASE testdb')\n        result = node.execute('SELECT 1')\n        print(result)\n        # Node is automatically stopped and cleaned up\n","lang":"python","description":"Quickstart demonstrating starting a temporary PostgreSQL node, initializing, starting, creating a database, and executing a query."},"warnings":[{"fix":"Use unique names (e.g., with test name or random suffix) for each node.","message":"testgres.get_new_node() requires a node name that is unique per test session. Reusing names across tests may cause conflicts.","severity":"gotcha","affected_versions":"all"},{"fix":"Specify port range via `port=50432` or use `testgres.get_new_node('node', port=50432)`.","message":"The temporary PostgreSQL instance uses a port assigned by the OS. If multiple tests run concurrently, port collisions can occur. Use the 'port' parameter to specify a range or fixed port.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `node.execute('query', returns='text')` to get string output, or adapt to list-of-tuples.","message":"The `execute()` method returns a list of tuples by default; in older versions it returned a string. If you rely on string output, update your code.","severity":"deprecated","affected_versions":"< 1.13.0"},{"fix":"Wrap in try/finally or use `with` context manager which handles cleanup on normal exit, but on exception you may need manual `node.stop()` and `node.cleanup()`.","message":"testgres nodes do not automatically clean up the data directory if the context manager exits due to an exception. Use explicit cleanup or catch exceptions.","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":"Run `pip install testgres` and ensure the correct virtual environment is activated.","cause":"testgres is not installed or the virtual environment does not include it.","error":"ImportError: No module named 'testgres'"},{"fix":"Ensure you call `node.start()` and wait for readiness, e.g., `node.wait_for_ready()`.","cause":"The PostgreSQL node may not have started fully before attempting a connection.","error":"psycopg2.OperationalError: could not connect to server: Connection refused"},{"fix":"Install PostgreSQL server and ensure its bin directory is in PATH, or set `pg_bindir` parameter to the PostgreSQL bin directory.","cause":"PostgreSQL binaries (initdb, pg_ctl) are not in the system PATH.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'initdb'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}