Run and write tests#
All functionality in orix is tested with pytest.
The tests reside in a
Tests are short methods that call functions in
orix and compare resulting output
values with known answers. Install necessary dependencies to run the tests:
pip install --editable .[tests]
If you get an error message running the above in a
zsh shell, try wrapping the last
part in a string, like
Some useful fixtures are available in the
orix.data module tests check that data not part of the package
distribution can be downloaded from the web, thus downloading some small datasets to
your local cache. See the section on the
data module for more details.
To run the tests:
pytest --cov --pyargs orix
--cov flag makes coverage.py prints a nice report in the
For an even nicer presentation, you can use
Then, you can open the created
htmlcov/index.html in the browser and inspect the
coverage in more detail.
Docstring examples are tested with pytest as well.
matplotlib.pyplot should not be imported in examples as they are
already available in the namespace as
The docstring tests can be run from the top directory:
pytest --doctest-modules --ignore-glob=orix/tests orix/*.py
Tips for writing tests of Numba decorated functions:
A Numba decorated function
numba_func()is only covered if it is called in the test as
Always test a Numba decorated function calling
numba_func()directly, in addition to
numba_func.py_func(), because the machine code function might give different results on different OS with the same Python code.