datadir-mgr plugin for pytest
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.
is pathlib-based, so complete paths to data files are handled,
not just filenames.
This plugin 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:
downloadmethod allows downloading data files into data directories, with option MD5 checksum checks, un-gzipping, and a progressbar.
savepathfixture lets an arbitrary path relative to the current working directory to be saved at a particular scope in the data directories.
add_scopemethod 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.
in_tmp_dirmethod 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
_testcould be confused with scope directories and cannnot be saved. If
progressbaris 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.
paths_from_scopereturns a list of all paths to files from a specified scope.
Python 3.6 or greater is required. This package is tested under Linux, MacOS, and Windows using Python 3.9.