Skip to main content

pytest plugin for test data directories and files

Project description


pytest plugin for manipulating test data directories and files.

Build Status PyPI PythonVersions CondaForge


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

You can access the contents of these files using injected variables datadir (for test_ folder) or shared_datadir (for data folder):

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.


Follow these steps to make a new release:

  1. Create a new branch release-X.Y.Z from master.
  2. Update CHANGELOG.rst.
  3. Open a PR.
  4. After it is green and approved, push a new tag in the format X.Y.Z.

Travis will deploy to PyPI automatically.

Afterwards, update the recipe in conda-forge/pytest-datadir-feedstock.



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pytest-datadir, version 1.3.1
Filename, size File type Python version Upload date Hashes
Filename, size pytest_datadir-1.3.1-py2.py3-none-any.whl (5.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size pytest-datadir-1.3.1.tar.gz (15.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page