Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added documentation for patch in #16817 #120

Closed
wants to merge 1 commit into from

2 participants

@pvl
pvl commented

Included the patch in #16817 and added documentation for using coverage installation and use (also based on the documentation work of krzysiumed in #4501)

@pvl pvl Included the patch in #16817 and added documentation for using covera…
…ge installation and use (also based on the documentation work of krzysiumed in #4501)
c59a0f9
@timgraham
Owner

Thanks! I've modified this a bit and merged it.

@timgraham timgraham closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 7, 2012
  1. @pvl

    Included the patch in #16817 and added documentation for using covera…

    pvl authored
    …ge installation and use (also based on the documentation work of krzysiumed in #4501)
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -2,3 +2,5 @@
*.pot
*.py[co]
docs/_build/
+tests/coverage_html/
+tests/.coverage
View
2  .hgignore
@@ -4,3 +4,5 @@ syntax:glob
*.pot
*.py[co]
docs/_build/
+tests/coverage_html/
+tests/.coverage
View
19 docs/internals/contributing/writing-code/unit-tests.txt
@@ -165,6 +165,25 @@ associated tests will be skipped.
.. _gettext: http://www.gnu.org/software/gettext/manual/gettext.html
.. _selenium: http://pypi.python.org/pypi/selenium
+Code coverage
+~~~~~~~~~~~~~
+
+Contributors are encouraged to run coverage on the test suite to identify areas that need additional testing work. The coverage tool installation and use is described in the :ref:`testing code coverage section<topics-testing-code-coverage>`.
+
+To run coverage on the Django test code using the standard test settings:
+
+.. code-block:: bash
+
+ coverage run ./runtests.py --settings=test_sqlite
+
+After running coverage, to generate the html report:
+
+.. code-block:: bash
+
+ coverage html
+
+When running coverage for the Django tests, the included ``.coveragerc`` settings file defines ``coverage_html`` as the output directory for the report and also excludes from coverage several directories not relevant to the results (test code or external code included in Django).
+
.. _contrib-apps:
Contrib apps
View
37 docs/topics/testing.txt
@@ -545,6 +545,43 @@ failed and erroneous tests. If all the tests pass, the return code is 0. This
feature is useful if you're using the test-runner script in a shell script and
need to test for success or failure at that level.
+.. _topics-testing-code-coverage:
+
+Code Coverage
+-------------
+`Code coverage`_ is a measure of the parts of the code that are executed and the parts of the code not executed when a program is run. One important use of coverage tools is to identify sections of code that are not executed as part of the test suite.
+
+When developing Django applications it is good practice to run ``coverage`` on the test suite to identify sections of the code base that need more test cases.
+
+The most popular python coverage module is coverage.py_ and it can be installed with the standard pip command:
+
+.. _Code coverage: http://en.wikipedia.org/wiki/Code_coverage
+.. _coverage.py: http://pypi.python.org/pypi/coverage
+
+.. code-block:: bash
+
+ pip install coverage
+
+To run coverage just for a Django application use the ``--source`` flag to restrict the source files analyzed. For example, in order to test and analyze only ``myapp``:
+
+.. code-block:: bash
+
+ coverage run --source=myapp manage.py test myapp
+
+Then either generate a quick report:
+
+.. code-block:: bash
+
+ coverage report
+
+Or generate a better looking and more informative html report with:
+
+.. code-block:: bash
+
+ coverage html
+
+The html report will be written by default to the ``htmlcov`` directory.
+
Testing tools
=============
View
5 tests/.coveragerc
@@ -0,0 +1,5 @@
+[run]
+omit = runtests,test_sqlite,regressiontests*,modeltests*,*/django/contrib/*/tests*,*/django/utils/unittest*,*/django/utils/simplejson*,*/django/utils/importlib.py,*/django/test/_doctest.py,*/django/core/servers/fastcgi.py,*/django/utils/autoreload.py,*/django/utils/dictconfig.py
+
+[html]
+directory = coverage_html
Something went wrong with that request. Please try again.