Tests in HuracanPy#
Running tests#
Tests are run using pytest. Simply run
pytest from the top of your repository and it will run all the existing tests.
If you want to run the tests across multiple python versions use tox.
Instead, run tox from the top of your repository, and tox will build a virtual environment for each python version supported by huracanpy and run the tests for each version.
Note, the python versions need to be installed on your system for tox to build the environments.
I used conda environments and symlinks to achieve this.
I don’t know if that’s how you’re supposed to do it.
Generally pytest should be sufficient for testing.
GitHub will run the tests over different python versions for pull requests, so tox can be useful if GitHub gives unexpected failures.
Writing tests#
Tests are kept in the tests folder.
The structure of this folder largely mimics the structure of huracanpy, but with folders/files/functions named test_*.
To add your test, add an appropriately named function/file/folder and use some kind of assert
statement to check the results.
Typically we are using
assert- The old classicnp.testing.assert_equal- Check two numpy arrays or array-like objects are equivalent, including if NaNs are presentnp.testing.assert_allclose- Check two numpy arrays or array-like objects are equivalent within a given tolerance for floating-point errorsxr.testing.assert_identical- Check that two xarray objects are the same, including all metadata
In tests/conftest.py are some pre-defined fixtures that can be useful for testing.
The simplest use is to include the name of the fixture as an argument to your test function, and then the fixture can be used in that test.
See the pytest documentation for more details.