pydocks


Namepydocks JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryPytest fixures for running tests with Docker containers
upload_time2024-09-26 12:02:45
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords containers docker pydocks pytest test
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 containers
- 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, pydocks, pytest, test",
    "author": null,
    "author_email": "Sylvain Mouquet <sylvain.mouquet@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/77/07/ff1222b4fa3d3c4eb15ea946694f6b00ae3d3679f0e71dc0104b7226e8b2/pydocks-1.0.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 containers\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.0.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/ppydocks"
    },
    "split_keywords": [
        "containers",
        " docker",
        " pydocks",
        " pytest",
        " test"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "137c179a94b67ef7f593f1faadd22c8d3a452c5985aa36140f4a419a430f295c",
                "md5": "faa9b6e0812ca4eb12ca3cd32b576606",
                "sha256": "6275539fb8a54afae3cc56b2dbc3ca3ed510dcc1a6f533da4730e0a2eb3e227f"
            },
            "downloads": -1,
            "filename": "pydocks-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "faa9b6e0812ca4eb12ca3cd32b576606",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6213,
            "upload_time": "2024-09-26T12:02:44",
            "upload_time_iso_8601": "2024-09-26T12:02:44.370976Z",
            "url": "https://files.pythonhosted.org/packages/13/7c/179a94b67ef7f593f1faadd22c8d3a452c5985aa36140f4a419a430f295c/pydocks-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7707ff1222b4fa3d3c4eb15ea946694f6b00ae3d3679f0e71dc0104b7226e8b2",
                "md5": "58f16e75faec509f6ae67412eb8237f9",
                "sha256": "c7a59bc196b193483d2e9cb954f729ad5d35d9a009eafde6af18176c5e5e12ed"
            },
            "downloads": -1,
            "filename": "pydocks-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "58f16e75faec509f6ae67412eb8237f9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 34861,
            "upload_time": "2024-09-26T12:02:45",
            "upload_time_iso_8601": "2024-09-26T12:02:45.411068Z",
            "url": "https://files.pythonhosted.org/packages/77/07/ff1222b4fa3d3c4eb15ea946694f6b00ae3d3679f0e71dc0104b7226e8b2/pydocks-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-26 12:02:45",
    "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: 1.19135s