Tests
OpenFisca has three sorts of tests:
- unit tests
- test-case tests
- scenario tests
Run tests
OpenFisca uses nose to run its unit tests. Here are some useful commands.
- Run the whole test suite:
which is available at least in Core, France and Web-API repositories.make test - Run a specific test:
nosetests openfisca_france/tests/test_legislations.py - Hide log of failing test:
nosetests --nologcapture openfisca_france/tests/test_legislations.py - Display log of successful test:
nosetests --debug=openfisca_core openfisca_france/tests/test_legislations.py
YAML tests
In OpenFisca-France run a YAML test like this:
python openfisca_france/tests/test_yaml.py openfisca_france/tests/formulas/psoc.yaml
To add tests for a formula, add a YAML file in openfisca_france/tests/formulas/, taking example on the existing ones.
To execute the tests for a specific YAML file, run openfisca_france/tests/test_yaml.py <path/to/file.yaml>.
Ignored tests
In OpenFisca-France some YAML tests are ignored. They receive a property ignored: true (example).
Some tests written in Python were ignored. They are now deleted and put aside in the
deleted-testsbranch, see the oldMakefile.
ipdb debugger
If a test fails, you can execute it with the debug nose plugin:
nosetests --pdb openfisca_core/tests/test_tax_scales.py
You can even specify the exact test to launch:
nosetests --pdb openfisca_core/tests/test_tax_scales.py:test_linear_average_rate_tax_scale
The nose-ipdb plugin is more user-friendly (because it uses the ipdb debugger instead of pdb).
In this case, just use the
--ipdboption rather than--pdb.
Travis automated tests
OpenFisca uses Travis CI to run tests automatically after each git push.
The repositories tested by Travis are:
The OpenFisca website hosts a summary page of the build statuses: http://www.openfisca.fr/build-status
Travis tests other git branches than master too. For example: OpenFisca-Core.
For OpenFisca-France, when testing a branch, if there is a branch in OpenFisca-Core with the same name, Travis will checkout it before running the tests. This is done by this script.
Idem for OpenFisca-Web-API with this script which is sightly different because it handles more dependencies.
Ludwig tests
To download tests from Ludwig (the tests tool from Mes aides), see the script download_mes_aides_tests.py.