OLD | NEW |
| (Empty) |
1 .. _config: | |
2 | |
3 =================== | |
4 Configuration files | |
5 =================== | |
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 | |
13 | |
14 Coverage.py options can be specified in a configuration file. This makes it | |
15 easier to re-run coverage with consistent settings, and also allows for | |
16 specification of options that are otherwise only available in the | |
17 :ref:`API <api>`. | |
18 | |
19 Configuration files also make it easier to get coverage testing of spawned | |
20 sub-processes. See :ref:`subprocess` for more details. | |
21 | |
22 The default name for configuration files is ``.coveragerc``, in the same | |
23 directory coverage.py is being run in. Most of the settings in the | |
24 configuration file are tied to your source code and how it should be | |
25 measured, so it should be stored with your source, and checked into | |
26 source control, rather than put in your home directory. | |
27 | |
28 | |
29 Syntax | |
30 ------ | |
31 | |
32 A coverage.py configuration file is in classic .ini file format: sections are | |
33 introduced by a ``[section]`` header, and contain ``name = value`` entries. | |
34 Lines beginning with ``#`` or ``;`` are ignored as comments. | |
35 | |
36 Strings don't need quotes. Multi-valued strings can be created by indenting | |
37 values on multiple lines. | |
38 | |
39 Boolean values can be specified as ``on``, ``off``, ``true``, ``false``, ``1``, | |
40 or ``0`` and are case-insensitive. | |
41 | |
42 Environment variables can be substituted in by using dollar signs: ``$WORD`` | |
43 ``${WORD}`` will be replaced with the value of ``WORD`` in the environment. | |
44 A dollar sign can be inserted with ``$$``. Missing environment variables | |
45 will result in empty strings with no error. | |
46 | |
47 Many sections and values correspond roughly to commands and options in | |
48 the :ref:`command-line interface <cmd>`. | |
49 | |
50 Here's a sample configuration file:: | |
51 | |
52 # .coveragerc to control coverage.py | |
53 [run] | |
54 branch = True | |
55 | |
56 [report] | |
57 # Regexes for lines to exclude from consideration | |
58 exclude_lines = | |
59 # Have to re-enable the standard pragma | |
60 pragma: no cover | |
61 | |
62 # Don't complain about missing debug-only code: | |
63 def __repr__ | |
64 if self\.debug | |
65 | |
66 # Don't complain if tests don't hit defensive assertion code: | |
67 raise AssertionError | |
68 raise NotImplementedError | |
69 | |
70 # Don't complain if non-runnable code isn't run: | |
71 if 0: | |
72 if __name__ == .__main__.: | |
73 | |
74 ignore_errors = True | |
75 | |
76 [html] | |
77 directory = coverage_html_report | |
78 | |
79 | |
80 [run] | |
81 ----- | |
82 | |
83 These values are generally used when running product code, though some apply | |
84 to more than one command. | |
85 | |
86 ``branch`` (boolean, default False): whether to measure | |
87 :ref:`branch coverage <branch>` in addition to statement coverage. | |
88 | |
89 ``cover_pylib`` (boolean, default False): whether to measure the Python | |
90 standard library. | |
91 | |
92 ``data_file`` (string, default ".coverage"): the name of the data file to use | |
93 for storing or reporting coverage. | |
94 | |
95 ``include`` (multi-string): a list of filename patterns, the files to include | |
96 in measurement or reporting. See :ref:`source` for details. | |
97 | |
98 ``omit`` (multi-string): a list of filename patterns, the files to leave out | |
99 of measurement or reporting. See :ref:`source` for details. | |
100 | |
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 | |
105 ``source`` (multi-string): a list of packages or directories, the source to | |
106 measure during execution. See :ref:`source` for details. | |
107 | |
108 ``timid`` (boolean, default False): use a simpler but slower trace method. | |
109 Try this if you get seemingly impossible results. | |
110 | |
111 | |
112 .. _config_paths: | |
113 | |
114 [paths] | |
115 ------- | |
116 | |
117 The entries in this section are lists of file paths that should be | |
118 considered equivalent when combining data from different machines:: | |
119 | |
120 [paths] | |
121 source = | |
122 src/ | |
123 /jenkins/build/*/src | |
124 c:\myproj\src | |
125 | |
126 The names of the entries are ignored, you may choose any name that | |
127 you like. The value is a lists of strings. When combining data | |
128 with the ``combine`` command, two file paths will be combined | |
129 if they start with paths from the same list. | |
130 | |
131 The first value must be an actual file path on the machine where | |
132 the reporting will happen, so that source code can be found. | |
133 The other values can be file patterns to match against the paths | |
134 of collected data. | |
135 | |
136 See :ref:`cmd_combining` for more information. | |
137 | |
138 | |
139 [report] | |
140 -------- | |
141 | |
142 Values common to many kinds of reporting. | |
143 | |
144 ``exclude_lines`` (multi-string): a list of regular expressions. Any line of | |
145 your source code that matches one of these regexes is excluded from being | |
146 reported as missing. More details are in :ref:`excluding`. If you use this | |
147 option, you are replacing all the exclude regexes, so you'll need to also | |
148 supply the "pragma: no cover" regex if you still want to use it. | |
149 | |
150 ``ignore_errors`` (boolean, default False): ignore source code that can't be | |
151 found. | |
152 | |
153 ``include`` (multi-string): a list of filename patterns, the files to include | |
154 in reporting. See :ref:`source` for details. | |
155 | |
156 ``omit`` (multi-string): a list of filename patterns, the files to leave out | |
157 of reporting. See :ref:`source` for details. | |
158 | |
159 ``partial_branches`` (multi-string): a list of regular expressions. Any line | |
160 of code that matches one of these regexes is excused from being reported as | |
161 a partial branch. More details are in :ref:`branch`. If you use this option, | |
162 you are replacing all the partial branch regexes so you'll need to also | |
163 supply the "pragma: no branch" regex if you still want to use it. | |
164 | |
165 ``precision`` (integer): the number of digits after the decimal point to | |
166 display for reported coverage percentages. The default is 0, displaying | |
167 for example "87%". A value of 2 will display percentages like "87.32%". | |
168 | |
169 ``show_missing`` (boolean, default False): when running a summary report, | |
170 show missing lines. See :ref:`cmd_summary` for more information. | |
171 | |
172 | |
173 .. _config_html: | |
174 | |
175 [html] | |
176 ------ | |
177 | |
178 Values particular to HTML reporting. The values in the ``[report]`` section | |
179 also apply to HTML output, where appropriate. | |
180 | |
181 ``directory`` (string, default "htmlcov"): where to write the HTML report files. | |
182 | |
183 ``extra_css`` (string): the path to a file of CSS to apply to the HTML report. | |
184 The file will be copied into the HTML output directory. Don't name it | |
185 "style.css". This CSS is in addition to the CSS normally used, though you can | |
186 overwrite as many of the rules as you like. | |
187 | |
188 ``title`` (string, default "Coverage report"): the title to use for the report. | |
189 Note this is text, not HTML. | |
190 | |
191 | |
192 [xml] | |
193 ----- | |
194 | |
195 Values particular to XML reporting. The values in the ``[report]`` section | |
196 also apply to XML output, where appropriate. | |
197 | |
198 ``output`` (string, default "coverage.xml"): where to write the XML report. | |
OLD | NEW |