Skip to main content

Parameterize unit tests with values from YAML, TOML, and NT files.

Project description

https://img.shields.io/pypi/v/parametrize_from_file.svg https://img.shields.io/pypi/pyversions/parametrize_from_file.svg https://img.shields.io/readthedocs/parametrize_from_file.svg https://img.shields.io/github/workflow/status/kalekundert/parametrize_from_file/Test%20and%20release/master https://img.shields.io/coveralls/kalekundert/parametrize_from_file.svg

Parametrizing your tests—in other words, separating the test data from the test code—is frequently a good idea. It makes it easier to add new test cases, while also making it easier to read and understand the test code.

parametrize_from_file provides a convenient way to parametrize tests when using the popular pytest framework. The central idea is to keep the parameters in their own files, separate from the test code. This prevents long lists of parameters from dwarfing your test code, and often allows parameters to be specified more clearly and succinctly than would be possible in python. Below is the basic workflow that this package enables:

  • Write test cases in a JSON, YAML, TOML, or NestedText file:

    # test_misc.yml
    test_addition:
      - a: 1
        b: 2
        c: 3
  • Decorate the corresponding test functions with parametrize_from_file:

    # test_misc.py
    import parametrize_from_file
    
    @parametrize_from_file
    def test_addition(a, b, c):
        assert a + b == c
  • Run pytest as usual:

    $ pytest

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

parametrize_from_file-0.2.0.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

parametrize_from_file-0.2.0-py2.py3-none-any.whl (7.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file parametrize_from_file-0.2.0.tar.gz.

File metadata

  • Download URL: parametrize_from_file-0.2.0.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.9

File hashes

Hashes for parametrize_from_file-0.2.0.tar.gz
Algorithm Hash digest
SHA256 45f0fd60e08d933da8e9f02c7a269ab801c0d8fd9e2278b20261f8847015c6dc
MD5 f5621ba61efe3882b1e52e1d2b8c4759
BLAKE2b-256 77ba2c9aef467967ea46d09e26420ee9f627aba429d69e959ea4c5d671b20b30

See more details on using hashes here.

File details

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

File metadata

  • Download URL: parametrize_from_file-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.9

File hashes

Hashes for parametrize_from_file-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bbfeade2c6eec8f26eb7c05c33d90b4988a191abffc45eb1883a3656f875d1e4
MD5 69d1fe6d012a54cedb96365e0717a2dc
BLAKE2b-256 3e8b621dd7e26d07f2108830d6c95ce3540fb75ae57ecba7a3dea5e003cb99e5

See more details on using hashes here.

Supported by

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