Skip to main content

pytest plugin to provide data from files loaded automatically

Project description

Overview

[Github Actions: Test status]

A pytest plugin to provide fixtures to load test data from files automatically.

Usage

Fixtures

This plugin provides following fixtures for each test modules.

test_data_info

test_data_info provides a namedtuple object, data_from_files.ModuleInfo, has the following values for each test modules.

  • root: test root dir, <package_dir>/tests/ by default and is configurable with –test-root (test_root) option.

  • datadir: test data dir using the fixture will be searched under <root>/<test_data_dirname>/, where test_data_dirname is configurable with –test-data-dirname option.

    • if the test code using the fixture is tests/test_foo.py, then datadir becomes tests/data/foo/

    • if the test code using the fixture is tests/foo/bar/test_baz.py, then datadir becomes tests/data/foo/bar/baz

  • subdirs: names of sub dirs relative to datadir if such dirs exist.

test_data

test_data provides a list of or a list of lists of namedtuple objects, data_from_files.DataInfo, has the following values.

  • data: data loaded from a file <path> under <datadir>

  • path: a file path contains the data

  • datadir: dir contains the test data file

Options

  • –test-root: test root dir where test data are seached [<package_dir>/tests]

  • –test-data-dirname: test data dir name [data]

  • –test-data-pattern: test data file path pattern relative to datadir [**/*.*]

Examples

  • tests/test_plugin.py and test data under tests/data/plugin/

  • tests/test_plugin_no_data.py and test data under tests/data/plugin_no_data

  • tests/foo/test_bar.py and test data under tests/data/foo/bar

Installation

Requirements

  • pytest obviously

  • PyYAML [1] is optionally required to load data from YAML files

  • anyconfig [2] is optionally required to load data in formats anyconfig and/or its plugins support.

How to install

  • PyPI:

    pip install pytest_data_from_files
  • From git repo:

    pip install git+https://github.com/ssato/pytest-data-from-files
  • Build wheel and install it:

    tox -e dists && pip install dist/pytest_data_from_files-*.whl

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-data-from-files-0.2.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

pytest_data_from_files-0.2.0-py2.py3-none-any.whl (8.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pytest-data-from-files-0.2.0.tar.gz.

File metadata

  • Download URL: pytest-data-from-files-0.2.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.7

File hashes

Hashes for pytest-data-from-files-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c0efa8648914c415ce094c12418767a0e080712647c535bbdda63dcd6935f872
MD5 fda1efbeecf46733733caf00e80c46a8
BLAKE2b-256 e1426597d0f3abadf2e936c24723150868990af71bbff792a2f0a5897285cc7d

See more details on using hashes here.

File details

Details for the file pytest_data_from_files-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pytest_data_from_files-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.7

File hashes

Hashes for pytest_data_from_files-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3115600e2f81619b8b7619b8ef9a0a17e83a5afb3f5a6fef8d8f9b41d01b4ce4
MD5 02a9ba15ef59aa6e7101981d3fed0d33
BLAKE2b-256 90cf87655dc68fdbe0dc996f2075e012b9a2b68e3f4a85ecbcf636da4e5c53ae

See more details on using hashes here.

Supported by

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