Test Driven Development
=======================

**Pytest** has been included in the test environment and should be used.
A number of plugins have also been added to improve Pytest.

    * `pytest-watch <https://pypi.org/project/pytest-watch/>`_   - watches the directory and runs tests on changes
    * `pytest-testmon <https://testmon.org/>`_ - montiors what files are being changed and only runs those tests
    * `pytest-sugar <https://pivotfinland.com/pytest-sugar/>`_   - gives a nicer output
    * `pytest-django <https://pytest-django.readthedocs.io/en/latest/>`_ - django integration
    * `pytest-cov <https://pytest-cov.readthedocs.io/en/latest/>`_   - coverage reports
    * `coverage-badge <https://pypi.org/project/coverage-badge/>`_ - creates a coverage badge for the documentation site

Pytest can be run to continuously watch the application directory and run tests that relate to code that is being changed with this command:

.. code-block:: bash

    ptw -- --testmon


You can run tests by using one of:

* ``npm test`` - which will run all tests in ``hub/`` and also the flake8 linter
* ``pytest <path>`` - to run individual test files
* ``npm run coverage`` - which will run the tests, and output detailed coverage reports in `htmlcov/index.html`


You might also want to run type checks with `mypy`:

.. code-block:: bash

    mypy hub

If you use type annotations, this can be useful to run occasionally, though it also has quite noisy output.


Test Coverage
=============

.. image:: https://gitlab.com/carboncoop/hub/badges/master/coverage.svg
        :target: https://gitlab.com/carboncoop/hub/