pydocks


Namepydocks JSON
Version 1.5.0 PyPI version JSON
download
home_pageNone
SummaryPytest fixures for running tests with Docker containers
upload_time2024-12-14 16:03:10
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords containers docker postgresql pydocks pytest redis test vault
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyDocks

PyDocks is a group of pytest fixures for running tests with Docker containers

### Demonstration:

```python
@pytest.mark.asyncio
async def test_postgresql_execute_command(postgresql_container):
    # Connect to the PostgreSQL database
    conn = await asyncpg.connect(
        host="127.0.0.1",
        port=5433,
        user="postgres",
        password="postgres",
        database="postgres",
    )

    try:
        # Execute a simple command
        result = await conn.fetchval("SELECT 1")
        assert result == 1, "Failed to execute command on PostgreSQL"
    finally:
        # Close the connection
        await conn.close()

```

## Table of Contents

- [PyDocks](#PyDocks)
  - [Table of Contents](#table-of-contents)
  - [Description](#description)
  - [Installation](#installation)
  - [Usage](#usage)
  - [License](#license)
  - [Contact](#contact)

## Description

PyDocks is a Python library that provides a set of pytest fixtures for running tests with Docker containers. It simplifies the process of setting up, managing, and tearing down Docker containers during test execution.

Key features include:
- Easy integration with pytest
- Support for PostgreSQL, Hashicorp Vault containers, Redis
- Automatic container cleanup
- Configurable container settings
- Reusable session-scoped containers for improved test performance

PyDocks is designed to make testing with Docker containers more efficient and less error-prone, allowing developers to focus on writing tests rather than managing infrastructure.

## Installation

```bash
# Install the dependency
pip install pydocks
uv add pydocks
poetry add pydocks
```

## Usage

### Remove all old containers
```python
import pytest_asyncio

@pytest_asyncio.fixture(scope="session", loop_scope="session", autouse=True)
async def begin_clean_all_containers(postgresql_clean_all_containers):
    logger.info("Begin - clean all containers")
```

### Use a function container
```python
@pytest.mark.asyncio
async def test_postgresql_execute_command(postgresql_container):
  ...
```

### Use a session container, to keep the container to use it in multiple tests
```python
@pytest.mark.asyncio(loop_scope="session")
async def test_reuse_postgresql_container_1_2(postgresql_container_session):
  ...
  # postgresql_container_session creates a new container

@pytest.mark.asyncio(loop_scope="session")
async def test_reuse_postgresql_container_2_2(postgresql_container_session):
  ...
  # postgresql_container_session uses the same instance of container created in test_reuse_postgresql_container_1_2
```


## License

PyDocks is released under the MIT License. See the [LICENSE](LICENSE) file for more details.

## Contact

For questions, suggestions, or issues related to PyDocks, please open an issue on the GitHub repository.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pydocks",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "containers, docker, postgresql, pydocks, pytest, redis, test, vault",
    "author": null,
    "author_email": "Sylvain Mouquet <sylvain.mouquet@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/b1/9e/ce722174170dc612495316ab06b07ff3b4b19da381f86b79555eddf82ffd/pydocks-1.5.0.tar.gz",
    "platform": null,
    "description": "# PyDocks\n\nPyDocks is a group of pytest fixures for running tests with Docker containers\n\n### Demonstration:\n\n```python\n@pytest.mark.asyncio\nasync def test_postgresql_execute_command(postgresql_container):\n    # Connect to the PostgreSQL database\n    conn = await asyncpg.connect(\n        host=\"127.0.0.1\",\n        port=5433,\n        user=\"postgres\",\n        password=\"postgres\",\n        database=\"postgres\",\n    )\n\n    try:\n        # Execute a simple command\n        result = await conn.fetchval(\"SELECT 1\")\n        assert result == 1, \"Failed to execute command on PostgreSQL\"\n    finally:\n        # Close the connection\n        await conn.close()\n\n```\n\n## Table of Contents\n\n- [PyDocks](#PyDocks)\n  - [Table of Contents](#table-of-contents)\n  - [Description](#description)\n  - [Installation](#installation)\n  - [Usage](#usage)\n  - [License](#license)\n  - [Contact](#contact)\n\n## Description\n\nPyDocks is a Python library that provides a set of pytest fixtures for running tests with Docker containers. It simplifies the process of setting up, managing, and tearing down Docker containers during test execution.\n\nKey features include:\n- Easy integration with pytest\n- Support for PostgreSQL, Hashicorp Vault containers, Redis\n- Automatic container cleanup\n- Configurable container settings\n- Reusable session-scoped containers for improved test performance\n\nPyDocks is designed to make testing with Docker containers more efficient and less error-prone, allowing developers to focus on writing tests rather than managing infrastructure.\n\n## Installation\n\n```bash\n# Install the dependency\npip install pydocks\nuv add pydocks\npoetry add pydocks\n```\n\n## Usage\n\n### Remove all old containers\n```python\nimport pytest_asyncio\n\n@pytest_asyncio.fixture(scope=\"session\", loop_scope=\"session\", autouse=True)\nasync def begin_clean_all_containers(postgresql_clean_all_containers):\n    logger.info(\"Begin - clean all containers\")\n```\n\n### Use a function container\n```python\n@pytest.mark.asyncio\nasync def test_postgresql_execute_command(postgresql_container):\n  ...\n```\n\n### Use a session container, to keep the container to use it in multiple tests\n```python\n@pytest.mark.asyncio(loop_scope=\"session\")\nasync def test_reuse_postgresql_container_1_2(postgresql_container_session):\n  ...\n  # postgresql_container_session creates a new container\n\n@pytest.mark.asyncio(loop_scope=\"session\")\nasync def test_reuse_postgresql_container_2_2(postgresql_container_session):\n  ...\n  # postgresql_container_session uses the same instance of container created in test_reuse_postgresql_container_1_2\n```\n\n\n## License\n\nPyDocks is released under the MIT License. See the [LICENSE](LICENSE) file for more details.\n\n## Contact\n\nFor questions, suggestions, or issues related to PyDocks, please open an issue on the GitHub repository.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Pytest fixures for running tests with Docker containers",
    "version": "1.5.0",
    "project_urls": {
        "changelog": "https://github.com/sylvainmouquet/pydocks/releases",
        "documentation": "https://github.com/sylvainmouquet/pydocks",
        "homepage": "https://github.com/sylvainmouquet/pydocks",
        "repository": "https://github.com/sylvainmouquet/pydocks"
    },
    "split_keywords": [
        "containers",
        " docker",
        " postgresql",
        " pydocks",
        " pytest",
        " redis",
        " test",
        " vault"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "429a8b0c344ddc61b187e6ccc455f768e0f6a0fa21fdb6fe12b5ffb24c18a17d",
                "md5": "0dc69e35c4a4ab24077a4798c7e42123",
                "sha256": "0fa0869d5c29e7f682b50f9a7f2cd2cf1a33861e30aa1dea912fa7fe58b1cb3c"
            },
            "downloads": -1,
            "filename": "pydocks-1.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0dc69e35c4a4ab24077a4798c7e42123",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 11043,
            "upload_time": "2024-12-14T16:03:08",
            "upload_time_iso_8601": "2024-12-14T16:03:08.266381Z",
            "url": "https://files.pythonhosted.org/packages/42/9a/8b0c344ddc61b187e6ccc455f768e0f6a0fa21fdb6fe12b5ffb24c18a17d/pydocks-1.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b19ece722174170dc612495316ab06b07ff3b4b19da381f86b79555eddf82ffd",
                "md5": "6e1c490579aeb275d5acfb596f2b58e5",
                "sha256": "1b34e9828fe3ee6998e02927d9fd2e886390f87a0c727b3bf163758dc50d7ddd"
            },
            "downloads": -1,
            "filename": "pydocks-1.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6e1c490579aeb275d5acfb596f2b58e5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 72897,
            "upload_time": "2024-12-14T16:03:10",
            "upload_time_iso_8601": "2024-12-14T16:03:10.628807Z",
            "url": "https://files.pythonhosted.org/packages/b1/9e/ce722174170dc612495316ab06b07ff3b4b19da381f86b79555eddf82ffd/pydocks-1.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-14 16:03:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sylvainmouquet",
    "github_project": "pydocks",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pydocks"
}
        
Elapsed time: 0.41856s