config.rst 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. .. Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
  2. .. For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
  3. .. _config:
  4. ===================
  5. Configuration files
  6. ===================
  7. .. :history: 20100223T201600, new for 3.3
  8. .. :history: 20100725T211700, updated for 3.4.
  9. .. :history: 20100824T092900, added ``precision``.
  10. .. :history: 20110604T184400, updated for 3.5.
  11. .. :history: 20110827T212700, updated for 3.5.1
  12. .. :history: 20130926T222300, updated for 3.6.1
  13. .. :history: 20140925T064700, updated for 4.0a1
  14. .. :history: 20150124T173400, updated for 4.0a4
  15. .. :history: 20150802T174600, updated for 4.0b1
  16. .. module:: coverage
  17. Coverage.py options can be specified in a configuration file. This makes it
  18. easier to re-run coverage.py with consistent settings, and also allows for
  19. specification of options that are otherwise only available in the
  20. :ref:`API <api>`.
  21. Configuration files also make it easier to get coverage testing of spawned
  22. sub-processes. See :ref:`subprocess` for more details.
  23. The default name for configuration files is ``.coveragerc``, in the same
  24. directory coverage.py is being run in. Most of the settings in the
  25. configuration file are tied to your source code and how it should be measured,
  26. so it should be stored with your source, and checked into source control,
  27. rather than put in your home directory.
  28. A different name for the configuration file can be specified with the
  29. ``--rcfile=FILE`` command line option.
  30. Coverage.py will read settings from a ``setup.cfg`` file if no other
  31. configuration file is used. In this case, the section names have "coverage:"
  32. prefixed, so the ``[run]`` options described below will be found in the
  33. ``[coverage:run]`` section of ``setup.cfg``.
  34. Syntax
  35. ------
  36. A coverage.py configuration file is in classic .ini file format: sections are
  37. introduced by a ``[section]`` header, and contain ``name = value`` entries.
  38. Lines beginning with ``#`` or ``;`` are ignored as comments.
  39. Strings don't need quotes. Multi-valued strings can be created by indenting
  40. values on multiple lines.
  41. Boolean values can be specified as ``on``, ``off``, ``true``, ``false``, ``1``,
  42. or ``0`` and are case-insensitive.
  43. Environment variables can be substituted in by using dollar signs: ``$WORD``
  44. or ``${WORD}`` will be replaced with the value of ``WORD`` in the environment.
  45. A dollar sign can be inserted with ``$$``. Missing environment variables
  46. will result in empty strings with no error.
  47. Many sections and values correspond roughly to commands and options in
  48. the :ref:`command-line interface <cmd>`.
  49. Here's a sample configuration file::
  50. # .coveragerc to control coverage.py
  51. [run]
  52. branch = True
  53. [report]
  54. # Regexes for lines to exclude from consideration
  55. exclude_lines =
  56. # Have to re-enable the standard pragma
  57. pragma: no cover
  58. # Don't complain about missing debug-only code:
  59. def __repr__
  60. if self\.debug
  61. # Don't complain if tests don't hit defensive assertion code:
  62. raise AssertionError
  63. raise NotImplementedError
  64. # Don't complain if non-runnable code isn't run:
  65. if 0:
  66. if __name__ == .__main__.:
  67. ignore_errors = True
  68. [html]
  69. directory = coverage_html_report
  70. .. _config_run:
  71. [run]
  72. -----
  73. These values are generally used when running product code, though some apply
  74. to more than one command.
  75. ``branch`` (boolean, default False): whether to measure
  76. :ref:`branch coverage <branch>` in addition to statement coverage.
  77. ``cover_pylib`` (boolean, default False): whether to measure the Python
  78. standard library.
  79. ``concurrency`` (multi-string, default "thread"): the name concurrency
  80. libraries in use by the product code. If your program uses `multiprocessing`_,
  81. `gevent`_, `greenlet`_, or `eventlet`_, you must name that library in this
  82. option, or coverage.py will produce very wrong results.
  83. .. _multiprocessing: https://docs.python.org/2/library/multiprocessing.html
  84. .. _greenlet: http://greenlet.readthedocs.org/en/latest/
  85. .. _gevent: http://www.gevent.org/
  86. .. _eventlet: http://eventlet.net/
  87. Before version 4.2, this option only accepted a single string.
  88. .. versionadded:: 4.0
  89. ``data_file`` (string, default ".coverage"): the name of the data file to use
  90. for storing or reporting coverage. This value can include a path to another
  91. directory.
  92. ``debug`` (multi-string): a list of debug options. See :ref:`the run
  93. --debug option <cmd_run_debug>` for details.
  94. ``include`` (multi-string): a list of file name patterns, the files to include
  95. in measurement or reporting. See :ref:`source` for details.
  96. ``note`` (string): an arbitrary string that will be written to the data file.
  97. You can use the :meth:`CoverageData.run_infos` method to retrieve this string
  98. from a data file.
  99. ``omit`` (multi-string): a list of file name patterns, the files to leave out
  100. of measurement or reporting. See :ref:`source` for details.
  101. ``parallel`` (boolean, default False): append the machine name, process
  102. id and random number to the data file name to simplify collecting data from
  103. many processes. See :ref:`cmd_combining` for more information.
  104. ``plugins`` (multi-string): a list of plugin package names. See :ref:`plugins`
  105. for more information.
  106. ``source`` (multi-string): a list of packages or directories, the source to
  107. measure during execution. See :ref:`source` for details.
  108. ``timid`` (boolean, default False): use a simpler but slower trace method.
  109. Try this if you get seemingly impossible results.
  110. .. _config_paths:
  111. [paths]
  112. -------
  113. The entries in this section are lists of file paths that should be considered
  114. equivalent when combining data from different machines::
  115. [paths]
  116. source =
  117. src/
  118. /jenkins/build/*/src
  119. c:\myproj\src
  120. The names of the entries are ignored, you may choose any name that you like.
  121. The value is a lists of strings. When combining data with the ``combine``
  122. command, two file paths will be combined if they start with paths from the same
  123. list.
  124. The first value must be an actual file path on the machine where the reporting
  125. will happen, so that source code can be found. The other values can be file
  126. patterns to match against the paths of collected data, or they can be absolute
  127. or relative file paths on the current machine.
  128. See :ref:`cmd_combining` for more information.
  129. .. _config_report:
  130. [report]
  131. --------
  132. Values common to many kinds of reporting.
  133. ``exclude_lines`` (multi-string): a list of regular expressions. Any line of
  134. your source code that matches one of these regexes is excluded from being
  135. reported as missing. More details are in :ref:`excluding`. If you use this
  136. option, you are replacing all the exclude regexes, so you'll need to also
  137. supply the "pragma: no cover" regex if you still want to use it.
  138. ``fail_under`` (integer): a target coverage percentage. If the total coverage
  139. measurement is under this value, then exit with a status code of 2.
  140. ``ignore_errors`` (boolean, default False): ignore source code that can't be
  141. found, emitting a warning instead of an exception.
  142. ``include`` (multi-string): a list of file name patterns, the files to include
  143. in reporting. See :ref:`source` for details.
  144. ``omit`` (multi-string): a list of file name patterns, the files to leave out
  145. of reporting. See :ref:`source` for details.
  146. ``partial_branches`` (multi-string): a list of regular expressions. Any line
  147. of code that matches one of these regexes is excused from being reported as
  148. a partial branch. More details are in :ref:`branch`. If you use this option,
  149. you are replacing all the partial branch regexes so you'll need to also
  150. supply the "pragma: no branch" regex if you still want to use it.
  151. ``precision`` (integer): the number of digits after the decimal point to
  152. display for reported coverage percentages. The default is 0, displaying for
  153. example "87%". A value of 2 will display percentages like "87.32%".
  154. ``show_missing`` (boolean, default False): when running a summary report, show
  155. missing lines. See :ref:`cmd_summary` for more information.
  156. ``skip_covered`` (boolean, default False): Don't include files in the report
  157. that are 100% covered files. See :ref:`cmd_summary` for more information.
  158. ``sort`` (string, default "Name"): Sort the text report by the named column.
  159. Allowed values are "Name", "Stmts", "Miss", "Branch", "BrPart", or "Cover".
  160. .. _config_html:
  161. [html]
  162. ------
  163. Values particular to HTML reporting. The values in the ``[report]`` section
  164. also apply to HTML output, where appropriate.
  165. ``directory`` (string, default "htmlcov"): where to write the HTML report files.
  166. ``extra_css`` (string): the path to a file of CSS to apply to the HTML report.
  167. The file will be copied into the HTML output directory. Don't name it
  168. "style.css". This CSS is in addition to the CSS normally used, though you can
  169. overwrite as many of the rules as you like.
  170. ``title`` (string, default "Coverage report"): the title to use for the report.
  171. Note this is text, not HTML.
  172. .. _config_xml:
  173. [xml]
  174. -----
  175. Values particular to XML reporting. The values in the ``[report]`` section
  176. also apply to XML output, where appropriate.
  177. ``output`` (string, default "coverage.xml"): where to write the XML report.
  178. ``package_depth`` (integer, default 99): controls which directories are
  179. identified as packages in the report. Directories deeper than this depth are
  180. not reported as packages. The default is that all directories are reported as
  181. packages.