Parametrize From File

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
    - str: sir lancelot
      sub: lance
      loc: 4
    - str: sir robin
      sub: brave
      loc: -1
  • Decorate the corresponding test functions with @parametrize_from_file:

    import 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 ..                                                       [100%]
    ============================== 2 passed in 0.09s ===============================