1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
Testing
=======
All tests can be run using `tox <https://tox.wiki/en/latest/>`_ simply by running the `tox` command. By default, tests
are run against a local sqlite2 instance. `pyenv <https://github.com/pyenv/pyenv>`_ can be used to manage multiple
python installations.
MySql / Postgres tests
######################
By using Docker, you can also run tests against either a MySQL db and/or Postgres.
The ``IMPORT_EXPORT_TEST_TYPE`` must be set according to the type of tests you wish to run. Set to 'postgres' for
postgres tests, and 'mysql-innodb' for mysql tests. If this environment variable is blank (or is any other value) then
the default sqlite2 db will be used.
This process is scripted in ``runtests.sh``. Assuming that you have docker installed on your system, running
``runtests.sh`` will run tox against sqlite2, mysql and postgres. You can edit this script to customise testing as you
wish.
Note that this is the process which is undertaken by CI builds.
Coverage
########
Coverage data is written in parallel mode by default (defined in ``pyproject.toml``).
A simple coverage report can be obtained with
.. code-block:: bash
make coverage
However this may omit lines which are db specific. A full coverage report can be obtained by running tox.
After a tox run, you can view coverage data as follows:
.. code-block:: bash
# combine all coverage data generated by tox into one file
coverage combine
# produce an HTML coverage report
coverage html
Check the output of the above commands to locate the coverage HTML file.
Bulk testing
############
There is a helper script available to generate and profile bulk loads. See ``scripts/bulk_import.py``.
You can use this script by configuring environment variables as defined above, and then installing and running the test
application. In order to run the helper script, you will need to install ``make install-test-requirements``, and then add
`django-extensions` to `settings.py` (`INSTALLED_APPS`).
You can then run the script as follows:
.. code-block:: bash
# run creates, updates, and deletes
./manage.py runscript bulk_import
# pass 'create', 'update' or 'delete' to run the single test
./manage.py runscript bulk_import --script-args create
Enable logging
^^^^^^^^^^^^^^
You can see console SQL debug logging by updating the ``LOGGING`` block in `settings.py`::
LOGGING = {
"version": 1,
"handlers": {"console": {"class": "logging.StreamHandler"}},
"root": {
"handlers": ["console"],
},
"loggers": {
"django.db.backends": {"level": "DEBUG", "handlers": ["console"]},
}
}
|