Skip to content

Commit

Permalink
docs: improve developer tutorial on how to run tests, incl. coverage (#…
Browse files Browse the repository at this point in the history
…676)

* docs: improve developer tutorial on how to run tests, incl. coverage

* add a docker command for running a database to test against

* exclude jinja templates from coverage, see nedbat/coveragepy#1553

* use the new make command from PR #672

* correct syntax type for docker call

* add dollar signs

* small text improvements
  • Loading branch information
nhoening committed May 19, 2023
1 parent aecb395 commit da6fdf7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[run]
omit = */tests/*, */scripts/*
omit = */tests/*, */scripts/*, **/*.jinja, **/*.html, **/*.txt
29 changes: 22 additions & 7 deletions documentation/dev/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,40 @@ You can run automated tests with:

.. code-block:: bash
$ make test
$ make test
which behind the curtains installs dependencies and calls pytest.
which behind the curtains installs dependencies and calls ``pytest``.

A coverage report can be created like this:
However, a test database (postgres) is needed to run these tests. If you have postgres, here is the short version on how to add the test database:

.. code-block:: bash
$ pytest --cov=flexmeasures --cov-config .coveragerc
$ make clean-db db_name=flexmeasures_test db_user=flexmeasures_test
$ # the password for the db user is "flexmeasures_test"
.. note:: The section :ref:`host-data` has more details on using postgres for FlexMeasures.

Alternatively, if you don't feel like installing postgres for the time being, here is a docker command to provide a test database:

.. code-block:: bash
$ docker run --rm --name flexmeasures-test-db -e POSTGRES_PASSWORD=flexmeasures_test -e POSTGRES_DB=flexmeasures_test -e POSTGRES_USER=flexmeasures_test -p 5432:5432 -v ./ci/load-psql-extensions.sql:/docker-entrypoint-initdb.d/load-psql-extensions.sql -d postgres:latest
You can add --cov-report=html after which a htmlcov/index.html is generated.
.. warning:: This assumes that the port 5432 is not being used on your machine (for instance by an existing postgres database service).

If you want the tests to create a coverage report (printed on the terminal), you can run the ``pytest`` command like this:

.. code-block:: bash
$ pytest --cov=flexmeasures --cov-config .coveragerc
It's also possible to use:
You can add `--cov-report=html`, after which a file called `htmlcov/index.html` is generated.
Or, after a test run with coverage turned on as shown above, you can still generate it in another form:

.. code-block:: bash
$ python setup.py test
$ python3 -m coverage [html|lcov|json]
Expand Down

0 comments on commit da6fdf7

Please sign in to comment.