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