{"id":16652235,"url":"https://github.com/kprestel/pytest-docker-db","last_synced_at":"2025-07-22T23:34:49.276Z","repository":{"id":50210780,"uuid":"122113316","full_name":"kprestel/pytest-docker-db","owner":"kprestel","description":"A pytest plugin to use docker databases when running pytest","archived":false,"fork":false,"pushed_at":"2025-05-18T13:41:31.000Z","size":120,"stargazers_count":18,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-15T20:52:18.061Z","etag":null,"topics":["database","docker","pytest","pytest-fixtures","pytest-plugin","python-library","python3","testing"],"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/kprestel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-02-19T19:57:01.000Z","updated_at":"2024-03-26T07:20:53.000Z","dependencies_parsed_at":"2024-03-23T13:46:38.271Z","dependency_job_id":null,"html_url":"https://github.com/kprestel/pytest-docker-db","commit_stats":{"total_commits":43,"total_committers":2,"mean_commits":21.5,"dds":0.2558139534883721,"last_synced_commit":"5474780aec7cca8b8a05cbf43d7590b170fb6ec5"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/kprestel/pytest-docker-db","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kprestel%2Fpytest-docker-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kprestel%2Fpytest-docker-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kprestel%2Fpytest-docker-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kprestel%2Fpytest-docker-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kprestel","download_url":"https://codeload.github.com/kprestel/pytest-docker-db/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kprestel%2Fpytest-docker-db/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265506749,"owners_count":23778818,"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":["database","docker","pytest","pytest-fixtures","pytest-plugin","python-library","python3","testing"],"created_at":"2024-10-12T09:28:07.694Z","updated_at":"2025-07-22T23:34:49.255Z","avatar_url":"https://github.com/kprestel.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pytest-docker-db\n\nA plugin to use docker databases for pytests\n\n## What is this?\n\nThis is a pytest plugin that hooks into the host's :code:`docker` daemon to create and teardown containers within the pytest life cycle.\n\n## Features\n\n- Use custom :code:`Dockerfile`s or base images from `Dockerhub`\n- Use `volumes` to persist test data in between testing sessions\n- Specify what port you want the container to be listening on the host machine and the container\n- Optionally persist the container between test sessions\n- Name the containers created\n\n## Requirements\n\n- docker-py\u003e=6\n- pytest\u003e=7\n- docker\n\n## Installation\n\nYou can install `pytest-docker-db` via `pip` from `PyPI`\n\n```bash\npip install pytest-docker-db\n```\n\n## Configuration\n\n- db-volume-args\n\n  - Provide the \"-v\" arguments that you would pass to the\n    \"docker run\" command if you were using the cli. If you need\n    multiple volumes mounted separate them with commas.\n  - The basic syntax is :code:`/host/vol/path:/path/in/container:rw`.\n    If using a named volume, the syntax would be :code:`vol-name:/path/in/container:rw`\n    'For more information please visit the `docker documentation`'\n\n- db-image\n\n  - Specify the name of the image to use as the DB.\n\n    - Must be in the form of `\"image_name\":\"tag\"`.\n\n- db-name\n\n  - Specify the name of the container. If this is not specified a random container name will be\n    used with the prefix `docker-db`\n\n- db-host-port\n\n  - Specify the port that the db should be listening to on the host machine.\n\n- db-port\n\n  - Specify the port that the db should be listening to in the container.\n    This is often the default port used by your database.\n\n- db-persist-container\n\n  - If set, the container created will not be torn down after the test suite has ran.\n    By default any image created will be torn down and removed after the test suite has finished.\n\n- db-dockerfile\n\n  - Specify the name of the Dockerfile within the directory set as the :code:`db-build-context`\n\n    - If a path is given as well as an image name, the Dockerfile will be used.\n\n- db-docker-context\n\n  - The directory to use as the docker build context.\n\n- db-docker-env-vars\n\n  - A comma separated list of environment variables to pass to `docker run`\n    - `--db-docker-env-vars=FOO=BAR,PASSWORD=BAZ`\n\n## Usage\n\nPlugin contains one fixture:\n_docker_db_ - it's a session scoped fixture that returns a `docker-py container` object.\nFor almost all use cases the user will not care about this object.\n\nThe recommended way to use this fixture is to create an :code:`autouse=True` fixture in your `conftest.py` file to automatically invoke the setup of the containers.\n\n```python\n    @pytest.fixture(scope='session', autouse=True)\n    def my_docker_db(docker_db):\n        pass\n```\n\nCan be configured via the :code:`pytest` CLI or the :code:`pytest.ini` file.\n\npytest.ini:\n\n```ini\n    [pytest]\n    db-volume-args=/home/kp/vol:/var/lib/postgresql/data:rw\n    db-image=postgres:latest\n    db-name=test-postgres\n    db-port=5432\n    db-host-port=5434\n```\n\npytest CLI using a `Dockerhub`\n\n```bash\n    pytest --db-image=postgrest:latest --db-name=test-postgres --db-port=5432 --db-host-port=5434\n```\n\npytest CLI using a custom image\n\n```bash\n    pytest --db-dockerfile=Dockerfile --db-name=test-postgres --db-port=5432 --db-host-port=5434\n```\n\npytest CLI using a custom image and passing environment variables to it\n\n```bash\n    pytest --db-dockerfile=Dockerfile --db-name=test-postgres --db-port=5432 --db-host-port=5434 --db-docker-env-vars=POSTGRES_PASSWORD=FOO,POSTGRES_USER=BAR\n```\n\n## Contributing\n\nContributions are very welcome. Tests can be run with `tox`, please ensure\nthe coverage at least stays the same before you submit a pull request.\n\n## License\n\nDistributed under the terms of the `MIT` license, \"pytest-docker-db\" is free and open source software\n\n## Issues\n\nIf you encounter any problems, please file an issue along with a detailed description.\n\n`MIT`: http://opensource.org/licenses/MIT\n`file an issue`: https://github.com/kprestel/pytest-docker-db/issues\n`pytest`: https://github.com/pytest-dev/pytest\n`pip`: https://pypi.python.org/pypi/pip/\n`PyPI`: https://pypi.python.org/pypi\n`docker-py container`: http://docker-py.readthedocs.io/en/stable/containers.html\n`Dockerhub`: https://hub.docker.com/\n`docker documentation`: https://docs.docker.com/storage/volumes/#start-a-container-with-a-volume\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkprestel%2Fpytest-docker-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkprestel%2Fpytest-docker-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkprestel%2Fpytest-docker-db/lists"}