# 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": "http://github.com/gabrielcnr/pytest-datadir",
"name": "pytest-datadir",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "pytest test unittest directory file",
"author": "Gabriel Reis",
"author_email": "gabrielcnr@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/aa/97/a93900d82635aa3f419c3cd2059b4de7d7fe44e415eaf00c298854582dcc/pytest-datadir-1.5.0.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.5.0",
"project_urls": {
"Homepage": "http://github.com/gabrielcnr/pytest-datadir"
},
"split_keywords": [
"pytest",
"test",
"unittest",
"directory",
"file"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7c9096b9474cddda5ef9e10e6f1871c0fadfa153b605e0e749ba30437bfb62a0",
"md5": "dfe8a44043d2d044d2f0dec7a0ee8125",
"sha256": "34adf361bcc7b37961bbc1dfa8d25a4829e778bab461703c38a5c50ca9c36dc8"
},
"downloads": -1,
"filename": "pytest_datadir-1.5.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dfe8a44043d2d044d2f0dec7a0ee8125",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5095,
"upload_time": "2023-10-03T12:20:51",
"upload_time_iso_8601": "2023-10-03T12:20:51.091469Z",
"url": "https://files.pythonhosted.org/packages/7c/90/96b9474cddda5ef9e10e6f1871c0fadfa153b605e0e749ba30437bfb62a0/pytest_datadir-1.5.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "aa97a93900d82635aa3f419c3cd2059b4de7d7fe44e415eaf00c298854582dcc",
"md5": "8a5b6b1caa3c7414f76b21715f3bdd99",
"sha256": "1617ed92f9afda0c877e4eac91904b5f779d24ba8f5e438752e3ae39d8d2ee3f"
},
"downloads": -1,
"filename": "pytest-datadir-1.5.0.tar.gz",
"has_sig": false,
"md5_digest": "8a5b6b1caa3c7414f76b21715f3bdd99",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 8821,
"upload_time": "2023-10-03T12:20:52",
"upload_time_iso_8601": "2023-10-03T12:20:52.157473Z",
"url": "https://files.pythonhosted.org/packages/aa/97/a93900d82635aa3f419c3cd2059b4de7d7fe44e415eaf00c298854582dcc/pytest-datadir-1.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-03 12:20:52",
"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"
}