{"id":15574562,"url":"https://github.com/runfalk/tempdb","last_synced_at":"2025-06-18T23:35:50.169Z","repository":{"id":57473970,"uuid":"158130034","full_name":"runfalk/tempdb","owner":"runfalk","description":"Create temporary PostgreSQL clusters for unit tests","archived":false,"fork":false,"pushed_at":"2019-06-03T18:53:50.000Z","size":16,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-12T13:41:28.108Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/runfalk.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-18T21:46:02.000Z","updated_at":"2021-01-18T09:26:56.000Z","dependencies_parsed_at":"2022-09-10T13:02:34.197Z","dependency_job_id":null,"html_url":"https://github.com/runfalk/tempdb","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/runfalk/tempdb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runfalk%2Ftempdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runfalk%2Ftempdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runfalk%2Ftempdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runfalk%2Ftempdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/runfalk","download_url":"https://codeload.github.com/runfalk/tempdb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runfalk%2Ftempdb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260653875,"owners_count":23042645,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T18:19:10.619Z","updated_at":"2025-06-18T23:35:45.157Z","avatar_url":"https://github.com/runfalk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"TempDB\n======\nSpawn temporary PostgreSQL clusters for use in unit tests. This is alpha quality\nsoftware and the API may change between version.\n\n\nUsage\n-----\nThe following example shows how to create a temporary database with ``pytest``.\n\n.. code-block:: python\n\n    import psycopg2\n    import pytest\n\n    from contextlib import closing\n    from tempdb import find_postgres_bin_dir, PostgresFactory\n\n\n    @pytest.fixture\n    def conn():\n        # Try to discover a directory where PostgreSQL is installed. If you\n        # have installed it in a non-standard location you must replace\n        # pg_bin_dir with the path to the binary directory for your\n        # installation.\n        #\n        # It is possible to provide a specific version as an argument if there\n        # are multiple versions to choose from. The highest available version\n        # is chosen by default.\n        pg_bin_dir = find_postgres_bin_dir()\n        if pg_bin_dir is None:\n            pytest.skip(\"Unable to locate a PostgreSQL installation\")\n\n        # The factory is bound to a particular PostgreSQL version and can be\n        # used to create an arbitrary number of clusters\n        factory = PostgresFactory(pg_bin_dir)\n\n        # A cluster is an actual running instance of PostgreSQL. By default a\n        # cluster doesn't have any databases apart from the defaults. It is\n        # possible to create new databases using the method\n        # .create_database(name, template=None)\n        with closing(factory.create_temporary_cluster()) as cluster:\n            tmp_db = cluster.create_database(\"tmp\")\n            yield psycopg2.connect(tmp_db.dsn)\n\n\n    def test_create_tables(conn):\n        with conn.cursor() as c:\n            c.execute(\"\"\"\n                CREATE TABLE test(\n                    id SERIAL,\n                    name VARCHAR\n                )\n            \"\"\")\n            c.execute(\"INSERT INTO test(name) VALUES (%s), (%s)\", [\n                \"Abel\",\n                \"Cain\",\n            ])\n            c.execute(\"SELECT name FROM test ORDER BY id\")\n\n            assert [name for name, in c.fetchall()] == [\n                \"Abel\",\n                \"Cain\",\n            ]\n\n\nChangelog\n---------\n\nVersion 0.1.0\n~~~~~~~~~~~~~\nReleased on 3rd June, 2019\n\n- Initial release\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frunfalk%2Ftempdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frunfalk%2Ftempdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frunfalk%2Ftempdb/lists"}