A Python testing framework that makes it easy to write small tests and scales to complex functional testing for applications and libraries.
gabrielcnr/pytest-datadir
A pytest plugin that copies test data directories into temporary folders so tests can safely read and modify fixture files.
- Stars
- 277
- Forks
- 28
- Open issues
- 8
- Last commit
- 4 days ago
What is it?
pytest-datadir gives tests access to data files stored alongside them. By default, a test module named test_hello.py can use a matching test_hello/ directory through the datadir fixture, while a top-level data/ folder is exposed through shared_datadir. Both fixtures return pathlib.Path objects, so tests can use standard path operations to read files.
The contents of the data directory are copied to a temporary location for each test. Tests can write or modify files without affecting the original fixtures or other tests. The lazy_datadir and lazy_shared_datadir fixtures, added in version 1.7.0, copy files only when they are accessed through joinpath or the / operator, which avoids copying large directories that a test does not use.
Key features
- 01Exposes a module-specific data directory through the datadir fixture.
- 02Provides a shared data directory through the shared_datadir fixture.
- 03Copies data to a temporary folder so original files stay unchanged.
- 04Offers lazy_datadir and lazy_shared_datadir to copy files only when accessed.
- 05Returns pathlib.Path objects from the fixtures.
Use cases
- Storing sample input files or fixtures for parser and file-processing tests.
- Writing tests that create or modify files without touching the source fixtures.
- Sharing common test data across many test modules with one global data folder.
Things to know
- The repository metadata lists the license as NOASSERTION, while the README says MIT, so verify the license before use.
In collections
Topics
FAQ
- What is pytest-datadir?
- A pytest plugin that copies test data directories into temporary folders so tests can safely read and modify fixture files. pytest-datadir gives tests access to data files stored alongside them. By default, a test module named test_hello.py can use a matching test_hello/ directory through the datadir fixture, while a top-level data/ folder is exposed through shared_datadir. Both fixtures return pathlib.Path objects, so tests can use standard path operations to read files.
- Is pytest-datadir free to use? What license does it have?
- pytest-datadir is open source under the Other license. Check the license terms before using it in commercial products.
- Is pytest-datadir still maintained?
- Actively maintained. The last commit to pytest-datadir was on Nov 3, 2026.
- What can I use pytest-datadir for?
- Storing sample input files or fixtures for parser and file-processing tests. Writing tests that create or modify files without touching the source fixtures. Sharing common test data across many test modules with one global data folder.
- Where can I get pytest-datadir?
- The source code and installation instructions are on GitHub: https://github.com/gabrielcnr/pytest-datadir
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A Python package that generates fake data such as names, addresses, text and more, for seeding databases, testing and anonymizing data.
A Python library that generates fake but realistic data such as names, addresses, emails and financial values across 47 locales.
A Python library that records HTTP interactions made during tests and replays them later, so tests run offline and deterministically.
A pytest plugin that runs tests in parallel across multiple CPUs and adds a loop-on-failures mode.
A pytest plugin that lets test functions be coroutines, so you can await asyncio code directly inside tests.