Parametrize From File

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/actions/workflow/status/kalekundert/parametrize_from_file/test.yml?branch=master https://img.shields.io/coveralls/kalekundert/parametrize_from_file.svg https://img.shields.io/github/last-commit/kalekundert/parametrize_from_file?logo=github

Parametrize From File is a library for reading unit test parameters from config files. It works with the pytest framework. Below is the basic workflow that this package enables:

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

    # test_camelot.yml
    test_str_find:
    - str: sir lancelot
      sub: lance
      loc: 4
    
    - str: sir robin
      sub: brave
      loc: -1
    
  • Decorate the corresponding test functions with @parametrize_from_file:

    # test_camelot.py
    import parametrize_from_file
    
    @parametrize_from_file
    def test_str_find(str, sub, loc):
        assert str.find(sub) == loc
    
  • Run pytest as usual:

    ============================= test session starts ==============================
    platform linux -- Python 3.10.0, pytest-7.4.0, pluggy-1.2.0
    rootdir: /home/arthur/holy_grail
    collected 2 items
    
    test_camelot.py ..                                                       [100%]
    
    ============================== 2 passed in 0.09s ===============================