Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Manager for test data providing downloads, caching of generated files, and a context for temp directories.

Project description

The datadir-mgr plugin for pytest provides the datadir_mgr fixture which allow test functions to easily download data files and cache generated data files in data directories in a manner that allows for overlaying of results. datadir-mgr is pathlib-based, so complete paths to data files are handled, not just filenames.

The datadir_mgr behaves like a limited dictionary, with datadir_mgr[item] returning a path with the most specific scope (out of global, module, [class], [function] that matches the string or path specified by item. In addition to serving data files already stored in the data directory, the fixture provides five methods useful for adding to the test data stored in the repository:

  • The download method allows downloading data files into data directories, with option MD5 checksum checks, un-gzipping, and a progressbar.
  • The savepath fixture lets an arbitrary path relative to the current working directory to be saved at a particular scope in the data directories.
  • The add_scope method lets one add directories from scopes different from the present request to be added to the search path. This lets the results of previous cached steps to be used in scopes other than global.
  • The in_tmp_dir method creates a context in a temporary directory with a list of request file paths copied in. Optionally, all output file paths can be saved at a particular scope at cleanup with an optional exclusion filter pattern (e.g., for excluding log files). Note that files in directories that begin with test_ or end with _test could be confused with scope directories and cannnot be saved. If progressbar is set to “True”, then the progress of file copying will be shown, which is helpful in some long-running pytest jobs, e.g. on Travis.
  • The paths_from_scope returns a list of all paths to files from a specified scope.

Prerequisites

Python 3.6 or greater is required. This package is tested under Linux and MacOS using Python 3.8.

Installation for Users

Install via pip

pip install pytest-datadir-mgr

For Developers

If you plan to develop datadir_mgr, you’ll need to install the poetry dependency manager. If you haven’t previously installed poetry, execute the command:

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python

Next, get the master branch from GitHub

git clone https://github.com/joelb123/pytest-datadir-mgr.git

Change to the datadir-mgr/ directory and install with poetry:

poetry install -v

Test datadir-mgr with poetry:

poetry run pytest -s

Project Status

Latest Release Python package
Activity Download stats
License License terms
Build GitHub Actions
Coverage Codecov.io test coverage
Code Grade Codacy.io grade
Issues Issues reported

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-mgr, version 1.2.5
Filename, size File type Python version Upload date Hashes
Filename, size pytest_datadir_mgr-1.2.5-py3-none-any.whl (9.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pytest-datadir-mgr-1.2.5.tar.gz (10.0 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