Testing¶
This project uses unittest
for testing. Tests must be placed in
the tests directory. Each source module should have a corresponding
test module.
Running Tests¶
Tests can easily be run all or individually by invoking python with the
unittest
module:
python -m unittest
python -m unittest tests/test_db.py
If coverage
is installed, tests can also be run with coverage measurement:
coverage run --omit 'tests/*.py' --include './*' -m unittest
coverage report -m
coverage html
Afterwards a detailed coverage report is available in htmlconv/index.html
.
Test Variables¶
- DUMP_PAGES
Root directory to store generated html pages in. If unset, no pages are stored.
Common Fixtures¶
Note
Base test case classes define setUp()
and
tearDown()
. Subclasses that overwrite these,
must call super().methodName()
!
-
class
tests.
BaseTestCase
(methodName='runTest')¶ Base class for test cases that create temporary files
- Variables
self.dir (str) – Path to temporary working directory
-
class
tests.
BlankAppTestCase
(methodName='runTest')¶ Base class for test cases that operate on a blank flask app
The app instance will be configured for flask_sqlalchemy but without initialising the module.
- Variables
self.dir (str) – Path to temporary working directory
self.app (flask.Flask) – app instance
-
class
tests.
AppTestCase
(methodName='runTest')¶ Base class for test cases that operate on an instance of the project’s app
The app instance will be configured to use an empty database at a temporary location.
- Variables
self.dir (str) – Path to temporary working directory
self.app (flask.Flask) – app instance
self.client (flask.testing.FlaskClient) – test client
-
render_page
(name, url, *args, **kwargs)¶ Wrapper for
flask.Flask.test_client()
that optionally dumps page content