https://github.com/gabrielcnr/pytest-datadir
pytest plugin for manipulating test data directories and files
https://github.com/gabrielcnr/pytest-datadir
plugin pytest python tdd testdata testing
Last synced: 10 days ago
JSON representation
pytest plugin for manipulating test data directories and files
- Host: GitHub
- URL: https://github.com/gabrielcnr/pytest-datadir
- Owner: gabrielcnr
- License: other
- Created: 2015-07-02T21:41:44.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2025-03-31T18:17:42.000Z (about 2 months ago)
- Last Synced: 2025-04-06T12:05:40.872Z (about 2 months ago)
- Topics: plugin, pytest, python, tdd, testdata, testing
- Language: Python
- Size: 121 KB
- Stars: 255
- Watchers: 6
- Forks: 24
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.rst
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
- awesome-pytest - pytest-datadir - pytest plugin for manipulating test data directories and files (Plugins)
- best-of-python-dev - GitHub - 26% open · ⏱️ 29.04.2024): (Testing Tools)
README
# pytest-datadir
pytest plugin for manipulating test data directories and files.
[](https://github.com/gabrielcnr/pytest-datadir/workflows/build/badge.svg?branch=master)
[](https://pypi.python.org/pypi/pytest-datadir)
[](https://anaconda.org/conda-forge/pytest-datadir)

[](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.