/functional_tests/doc_tests/test_coverage_html/coverage_html.rst

https://bitbucket.org/jpellerin/nose/ · ReStructuredText · 57 lines · 47 code · 10 blank · 0 comment · 0 complexity · a1f45571503d158e803b32233b6ff128 MD5 · raw file

  1. Generating HTML Coverage with nose
  2. ----------------------------------
  3. .. Note ::
  4. HTML coverage requires Ned Batchelder's `coverage.py`_ module.
  5. ..
  6. Console coverage output is useful but terse. For a more browseable view of
  7. code coverage, the coverage plugin supports basic HTML coverage output.
  8. .. hide this from the actual documentation:
  9. >>> from nose.plugins.plugintest import run_buffered as run
  10. >>> import os
  11. >>> support = os.path.join(os.path.dirname(__file__), 'support')
  12. >>> cover_html_dir = os.path.join(support, 'cover')
  13. >>> cover_file = os.path.join(os.getcwd(), '.coverage')
  14. >>> if os.path.exists(cover_file):
  15. ... os.unlink(cover_file)
  16. ...
  17. The console coverage output is printed, as normal.
  18. >>> from nose.plugins.cover import Coverage
  19. >>> cover_html_dir = os.path.join(support, 'cover')
  20. >>> run(argv=[__file__, '-v', '--with-coverage', '--cover-package=blah',
  21. ... '--cover-html', '--cover-html-dir=' + cover_html_dir,
  22. ... support, ],
  23. ... plugins=[Coverage()]) # doctest: +REPORT_NDIFF
  24. test_covered.test_blah ... hi
  25. ok
  26. <BLANKLINE>
  27. Name Stmts Miss Cover Missing
  28. -------------------------------------
  29. blah 4 1 75% 6
  30. ----------------------------------------------------------------------
  31. Ran 1 test in ...s
  32. <BLANKLINE>
  33. OK
  34. The html coverage reports are saved to disk in the directory specified by the
  35. ``--cover-html-dir`` option. In that directory you'll find ``index.html``
  36. which links to a detailed coverage report for each module in the report. The
  37. detail pages show the module source, colorized to indicated which lines are
  38. covered and which are not. There is an example of this HTML output in the
  39. `coverage.py`_ docs.
  40. .. hide this from the actual documentation:
  41. >>> os.path.exists(cover_file)
  42. True
  43. >>> os.path.exists(os.path.join(cover_html_dir, 'index.html'))
  44. True
  45. >>> os.path.exists(os.path.join(cover_html_dir, 'blah.html'))
  46. True
  47. .. _`coverage.py`: http://nedbatchelder.com/code/coverage/