Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Added documentation for patch in #16817 #120

Closed
wants to merge 1 commit into from

2 participants

Pedro Lima Tim Graham
Pedro Lima
pvl commented June 07, 2012

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

Pedro Lima 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
Tim Graham
Owner

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

Tim Graham timgraham closed this October 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jun 07, 2012
Pedro Lima 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
This page is out of date. Refresh to see the latest.
2  .gitignore
@@ -2,3 +2,5 @@
2 2
 *.pot
3 3
 *.py[co]
4 4
 docs/_build/
  5
+tests/coverage_html/
  6
+tests/.coverage
2  .hgignore
@@ -4,3 +4,5 @@ syntax:glob
4 4
 *.pot
5 5
 *.py[co]
6 6
 docs/_build/
  7
+tests/coverage_html/
  8
+tests/.coverage
19  docs/internals/contributing/writing-code/unit-tests.txt
@@ -165,6 +165,25 @@ associated tests will be skipped.
165 165
 .. _gettext: http://www.gnu.org/software/gettext/manual/gettext.html
166 166
 .. _selenium: http://pypi.python.org/pypi/selenium
167 167
 
  168
+Code coverage 
  169
+~~~~~~~~~~~~~
  170
+
  171
+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>`.
  172
+
  173
+To run coverage on the Django test code using the standard test settings:
  174
+
  175
+.. code-block:: bash
  176
+
  177
+    coverage run ./runtests.py --settings=test_sqlite
  178
+
  179
+After running coverage, to generate the html report:
  180
+
  181
+.. code-block:: bash
  182
+
  183
+	coverage html
  184
+
  185
+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).
  186
+
168 187
 .. _contrib-apps:
169 188
 
170 189
 Contrib apps
37  docs/topics/testing.txt
@@ -545,6 +545,43 @@ failed and erroneous tests. If all the tests pass, the return code is 0. This
545 545
 feature is useful if you're using the test-runner script in a shell script and
546 546
 need to test for success or failure at that level.
547 547
 
  548
+.. _topics-testing-code-coverage:
  549
+
  550
+Code Coverage
  551
+-------------
  552
+`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. 
  553
+
  554
+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. 
  555
+
  556
+The most popular python coverage module is coverage.py_ and it can be installed with the standard pip command:
  557
+
  558
+.. _Code coverage: http://en.wikipedia.org/wiki/Code_coverage
  559
+.. _coverage.py: http://pypi.python.org/pypi/coverage
  560
+
  561
+.. code-block:: bash
  562
+
  563
+    pip install coverage
  564
+
  565
+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``: 
  566
+
  567
+.. code-block:: bash
  568
+
  569
+	coverage run --source=myapp manage.py test myapp
  570
+
  571
+Then either generate a quick report:
  572
+
  573
+.. code-block:: bash
  574
+
  575
+	coverage report
  576
+
  577
+Or generate a better looking and more informative html report with:
  578
+
  579
+.. code-block:: bash
  580
+
  581
+	coverage html
  582
+
  583
+The html report will be written by default to the ``htmlcov`` directory.
  584
+
548 585
 Testing tools
549 586
 =============
550 587
 
5  tests/.coveragerc
... ...
@@ -0,0 +1,5 @@
  1
+[run]
  2
+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
  3
+
  4
+[html]
  5
+directory = coverage_html
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.