yamltests is nose plugin for running tests written in YAML.
From the setup directory:
python setup.py install
Using pip:
pip install https://github.com/vpekar/yamltests/archive/master.zip
From the setup directory:
python tests.py
Add the --with-yaml-tests
option. Can be combined with other options, e.g., --with-coverage
:
nosetests --with-yaml-tests
To test the example package:
$ nosetests example --with-yamltests ..... ---------------------------------------------------------------------- Ran 6 tests in 0.014s OK
Should be as follows:
path.to.myModule: myFunctionInMyModule: description: "Extract twitter handle" text: "... @username ..." expected: "username" myClassInMyModule: myMethod: description: "Extract twitter handle" text: "... @username ..." expected: ["username"]
where text
is the input to the function/method being tested and expected
is its expected output.
Filenames should begin with "test" and have extension ".yml".
For a working example, see example/tests/tests.yml
.
Each function/method being tested can output either a string or a list. The expected value can be either a string or a list.
- If the expected value is a string and actual value is a string, assertEqual is used.
- If the expected value is a string and actual value is a list, assertIn is used.
- If the expected value is a list and actual value is a list, assertListEqual is used.
- If the yaml file contains a dot-separated module name (
SomePackage.SomeModule
) then the__init__.py
file inside SomePackage should explicitly import all modules (see the__init__.py
file in the example folder) - Optionally, the class being tested can be initialised with arguments (e.g., a mocked database) specified in
init_kwargs.py
, placed in the same folder as the test*.yml files. Seeinit_kwargs.py
in the example folder.