Skip to main content

pytest plugin for test data directories and files

Project description

pytest-datadir

pytest plugin for manipulating test data directories and files.

Build Status PyPI CondaForge Python Version Code style: 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):

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.

Project details


Download files

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

Source Distribution

pytest-datadir-1.5.0.tar.gz (8.8 kB view hashes)

Uploaded source

Built Distribution

pytest_datadir-1.5.0-py3-none-any.whl (5.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page