pytest-datadir


Namepytest-datadir JSON
Version 1.6.1 PyPI version JSON
download
home_pageNone
Summarypytest plugin for test data directories and files
upload_time2025-02-07 18:29:55
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords pytest test unittest directory file
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-datadir

pytest plugin for manipulating test data directories and files.

[![Build Status](https://github.com/gabrielcnr/pytest-datadir/workflows/build/badge.svg?branch=master)](https://github.com/gabrielcnr/pytest-datadir/workflows/build/badge.svg?branch=master)
[![PyPI](https://img.shields.io/pypi/v/pytest-datadir.svg)](https://pypi.python.org/pypi/pytest-datadir)
[![CondaForge](https://img.shields.io/conda/vn/conda-forge/pytest-datadir.svg)](https://anaconda.org/conda-forge/pytest-datadir)
![Python Version](https://img.shields.io/badge/python-3.6+-blue.svg)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)


# Usage
pytest-datadir will look up for a directory with the name of your module or the global 'data' folder.
Let's say you have a structure like this:

```
.
├── data/
│   └── hello.txt
├── test_hello/
│   └── spam.txt
└── test_hello.py
```
You can access the contents of these files using injected variables `datadir` (for *test_* folder) or `shared_datadir`
(for *data* folder):

```python
def test_read_global(shared_datadir):
    contents = (shared_datadir / "hello.txt").read_text()
    assert contents == "Hello World!\n"


def test_read_module(datadir):
    contents = (datadir / "spam.txt").read_text()
    assert contents == "eggs\n"
```

pytest-datadir will copy the original file to a temporary folder, so changing the file contents won't change the original data file.

Both `datadir` and `shared_datadir` fixtures are `pathlib.Path` objects.

# License

MIT.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pytest-datadir",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "pytest, test, unittest, directory, file",
    "author": null,
    "author_email": "Gabriel Reis <gabrielcnr@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/bb/0e/63301415b9233f0131339799d49ce0c0e8804d82f3f12615056a70e563c5/pytest_datadir-1.6.1.tar.gz",
    "platform": null,
    "description": "# pytest-datadir\n\npytest plugin for manipulating test data directories and files.\n\n[![Build Status](https://github.com/gabrielcnr/pytest-datadir/workflows/build/badge.svg?branch=master)](https://github.com/gabrielcnr/pytest-datadir/workflows/build/badge.svg?branch=master)\n[![PyPI](https://img.shields.io/pypi/v/pytest-datadir.svg)](https://pypi.python.org/pypi/pytest-datadir)\n[![CondaForge](https://img.shields.io/conda/vn/conda-forge/pytest-datadir.svg)](https://anaconda.org/conda-forge/pytest-datadir)\n![Python Version](https://img.shields.io/badge/python-3.6+-blue.svg)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n\n# Usage\npytest-datadir will look up for a directory with the name of your module or the global 'data' folder.\nLet's say you have a structure like this:\n\n```\n.\n\u251c\u2500\u2500 data/\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 hello.txt\n\u251c\u2500\u2500 test_hello/\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 spam.txt\n\u2514\u2500\u2500 test_hello.py\n```\nYou can access the contents of these files using injected variables `datadir` (for *test_* folder) or `shared_datadir`\n(for *data* folder):\n\n```python\ndef test_read_global(shared_datadir):\n    contents = (shared_datadir / \"hello.txt\").read_text()\n    assert contents == \"Hello World!\\n\"\n\n\ndef test_read_module(datadir):\n    contents = (datadir / \"spam.txt\").read_text()\n    assert contents == \"eggs\\n\"\n```\n\npytest-datadir will copy the original file to a temporary folder, so changing the file contents won't change the original data file.\n\nBoth `datadir` and `shared_datadir` fixtures are `pathlib.Path` objects.\n\n# License\n\nMIT.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "pytest plugin for test data directories and files",
    "version": "1.6.1",
    "project_urls": {
        "Homepage": "http://github.com/gabrielcnr/pytest-datadir"
    },
    "split_keywords": [
        "pytest",
        " test",
        " unittest",
        " directory",
        " file"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "55f15e4d95ce96c03332726d7fd87b7b500f178994b638ca6a88b4ed3ca64438",
                "md5": "b27dbd17d75e2990f90f5f84a604cca9",
                "sha256": "aa427f6218d3fc7481129d59c892bd7adfb8822613a2726ffc97f51968879cdb"
            },
            "downloads": -1,
            "filename": "pytest_datadir-1.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b27dbd17d75e2990f90f5f84a604cca9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5156,
            "upload_time": "2025-02-07T18:29:53",
            "upload_time_iso_8601": "2025-02-07T18:29:53.788474Z",
            "url": "https://files.pythonhosted.org/packages/55/f1/5e4d95ce96c03332726d7fd87b7b500f178994b638ca6a88b4ed3ca64438/pytest_datadir-1.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bb0e63301415b9233f0131339799d49ce0c0e8804d82f3f12615056a70e563c5",
                "md5": "454415167daa5c9040a7ea474939bf90",
                "sha256": "4d204cf93cfe62ddc37b19922df6c8c0f133c2899c224bd339b24920e84e7fd3"
            },
            "downloads": -1,
            "filename": "pytest_datadir-1.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "454415167daa5c9040a7ea474939bf90",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 9391,
            "upload_time": "2025-02-07T18:29:55",
            "upload_time_iso_8601": "2025-02-07T18:29:55.226021Z",
            "url": "https://files.pythonhosted.org/packages/bb/0e/63301415b9233f0131339799d49ce0c0e8804d82f3f12615056a70e563c5/pytest_datadir-1.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-07 18:29:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gabrielcnr",
    "github_project": "pytest-datadir",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-datadir"
}
        
Elapsed time: 0.48202s