| 1 | # pytest-datadir |
| 2 | |
| 3 | pytest plugin for manipulating test data directories and files. |
| 4 | |
| 5 | [](https://github.com/gabrielcnr/pytest-datadir/workflows/build/badge.svg?branch=master) |
| 6 | [](https://pypi.python.org/pypi/pytest-datadir) |
| 7 | [](https://anaconda.org/conda-forge/pytest-datadir) |
| 8 |  |
| 9 | [](https://github.com/psf/black) |
| 10 | |
| 11 | |
| 12 | # Usage |
| 13 | pytest-datadir will look up for a directory with the name of your module or the global 'data' folder. |
| 14 | Let's say you have a structure like this: |
| 15 | |
| 16 | ``` |
| 17 | . |
| 18 | ├── data/ |
| 19 | │ └── hello.txt |
| 20 | ├── test_hello/ |
| 21 | │ └── spam.txt |
| 22 | └── test_hello.py |
| 23 | ``` |
| 24 | You can access the contents of these files using injected variables `datadir` (for *test_* folder) or `shared_datadir` |
| 25 | (for *data* folder): |
| 26 | |
| 27 | ```python |
| 28 | def test_read_global(shared_datadir): |
| 29 | contents = (shared_datadir / "hello.txt").read_text() |
| 30 | assert contents == "Hello World!\n" |
| 31 | |
| 32 | |
| 33 | def test_read_module(datadir): |
| 34 | contents = (datadir / "spam.txt").read_text() |
| 35 | assert contents == "eggs\n" |
| 36 | ``` |
| 37 | |
| 38 | pytest-datadir will copy the original file to a temporary folder, so changing the file contents won't change the original data file. |
| 39 | |
| 40 | Both `datadir` and `shared_datadir` fixtures are `pathlib.Path` objects. |
| 41 | |
| 42 | # Releases |
| 43 | |
| 44 | Follow these steps to make a new release: |
| 45 | |
| 46 | 1. Create a new branch `release-X.Y.Z` from `master`. |
| 47 | 2. Update `CHANGELOG.rst`. |
| 48 | 3. Open a PR. |
| 49 | 4. After it is **green** and **approved**, push a new tag in the format `X.Y.Z`. |
| 50 | |
| 51 | Travis will deploy to PyPI automatically. |
| 52 | |
| 53 | Afterwards, update the recipe in [conda-forge/pytest-datadir-feedstock](https://github.com/conda-forge/pytest-datadir-feedstock). |
| 54 | |
| 55 | # License |
| 56 | |
| 57 | MIT. |