OpenFisca has three sorts of tests:
- unit tests
- test-case tests
- scenario 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.
- Run a specific test:
- Hide log of failing test:
nosetests --nologcapture openfisca_france/tests/test_parameters.py
- Display log of successful test:
nosetests --debug=openfisca_core openfisca_france/tests/test_parameters.py
Formulas are tested with YAML tests.
If a test fails, you can execute it with the debug nose plugin:
nosetests --pdb openfisca_core/tests/test_tax_scales.py
You'll be dropped in the
You can specify the exact test to launch:
nosetests --pdb openfisca_core/tests/test_tax_scales.py:test_linear_average_rate_tax_scale
In case you want to set a breakpoint manually, in order to enter the debugger shell before an errors occurs, copy-paste this line in your code:
import nose.tools; nose.tools.set_trace(); import ipdb; ipdb.set_trace()
This needs ipdb to be installed.
Hint: use the snippets feature of your favorite text editor to save this line, for example give it the name "breakpoint".
Travis automated tests
OpenFisca uses Travis CI to run tests automatically after each
The repositories tested by Travis are:
The OpenFisca website hosts a summary page of the build statuses: https://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.