Skip to content

Commit 140c97e

Browse files
committed
Update the docs for 3.5 changes.
1 parent 15addf2 commit 140c97e

File tree

6 files changed

+64
-24
lines changed

6 files changed

+64
-24
lines changed

TODO.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ Coverage TODO
55
+ warn if no data was collected
66
- tie --source into reporting
77

8-
* 3.5b1
9-
10-
- Update changes.rst
11-
- Document partial branch exclusion
12-
- Document HTML reporting
13-
- Keyboard shortcuts
14-
- Delta reporting
15-
16-
178
* Soon
189

1910
+ Better omit handling that ignores files during measurement.

doc/branch.rst

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Branch coverage measurement
66

77
:history: 20091127T201300, new for version 3.2
88
:history: 20100725T211700, updated for 3.4.
9+
:history: 20110604T181700, updated for 3.5.
910

1011
.. highlight:: python
1112
:linenothreshold: 5
@@ -30,7 +31,7 @@ or line 4. Statement coverage would show all lines of the function as executed.
3031
But the if was never evaluated as false, so line 2 never jumps to line 4.
3132

3233
Branch coverage will flag this code as not fully covered because of the missing
33-
jump from line 2 to line 4.
34+
jump from line 2 to line 4. This is known as a partial branch.
3435

3536

3637
How to measure branch coverage
@@ -86,18 +87,34 @@ Because the ``else`` clause is excluded, the ``if`` only has one possible
8687
next line, so it isn't considered a branch at all.
8788

8889

89-
Problems
90-
--------
90+
Structurally partial branches
91+
-----------------------------
9192

92-
Some Python constructs are difficult to measure properly. For example, an
93-
unconditional loop will be marked as partially executed::
93+
Sometimes branching constructs are used in unusual ways that don't actually
94+
branch. For example::
9495

95-
while True: # line 1
96-
if some_condition(): # 2
96+
while True:
97+
if cond:
9798
break
98-
body_of_loop() # 4
99+
do_something()
99100

100-
keep_working() # 6
101+
Here the while loop will never exit normally, so it doesn't take both of its
102+
"possible" branches. For some of these constructs, such as "while True:" and
103+
"if 0:", coverage.py understands what is going on. In these cases, the line
104+
will not be marked as a partial branch.
105+
106+
But there are many ways in your own code to write intentionally partial
107+
branches, and you don't want coverage.py pestering you about them. You can
108+
tell coverage.py that you don't want them flagged by marking them with a
109+
pragma::
110+
111+
i = 0
112+
while i < 999999999: # pragma: no partial
113+
if eventually():
114+
break
115+
116+
Here the while loop will never complete because the break will always be taken
117+
at some point. Coverage.py can't work that out on its own, but the
118+
"no partial" pragma indicates that the branch is known to be partial, and
119+
the line is not flagged.
101120

102-
Because the loop never terminates naturally (jumping from line 1 to 6),
103-
coverage.py considers the branch partially executed.

doc/cmd.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ If you are measuring coverage in a multi-process program, or across a number of
9292
machines, you'll want the ``--parallel-mode`` switch to keep the data separate
9393
during measurement. See :ref:`cmd_combining` below.
9494

95+
During execution, coverage.py may warn you about conditions it detects that
96+
could affect the measurement process. The possible warnings include:
97+
98+
* "Trace function changed, measurement is likely wrong"
99+
100+
* "Module has no Python source"
101+
102+
* "Module was never imported"
103+
104+
* "No data was collected"
105+
106+
95107

96108
.. _cmd_datafile:
97109

@@ -213,12 +225,20 @@ Lines are highlighted green for executed, red for missing, and gray for
213225
excluded. The counts at the top of the file are buttons to turn on and off
214226
the highlighting.
215227

228+
A number of keyboard shortcuts are available for navigating the report.
229+
Click the keyboard icon in the upper right to see the complete list.
230+
216231
The ``-d`` argument specifies an output directory, defaulting to "htmlcov"::
217232

218233
$ coverage html -d coverage_html
219234

220235
Other common reporting options are described above in :ref:`cmd_reporting`.
221236

237+
Generating the HTML report can be time-consuming. Stored with the HTML report
238+
is a data file that is used to speed up reporting the next time. If you
239+
generate a new report into the same directory, coverage.py will skip
240+
generating unchanged pages, making the process faster.
241+
222242

223243
.. _cmd_annotation:
224244

doc/config.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Configuration files
77
:history: 20100223T201600, new for 3.3
88
:history: 20100725T211700, updated for 3.4.
99
:history: 20100824T092900, added ``precision``.
10+
:history: 20110604T184400, updated for 3.5.
1011

1112

1213
Coverage.py options can be specified in a configuration file. This makes it
@@ -122,6 +123,12 @@ in reporting. See :ref:`source` for details.
122123
``omit`` (multi-string): a list of filename patterns, the files to leave out
123124
of reporting. See :ref:`source` for details.
124125

126+
``partial_branches`` (multi-string): a list of regular expressions. Any line
127+
of code that matches one of these regexes is excused from being reported as
128+
a partial branch. More details are in :ref:`branch`. If you use this option,
129+
you are replacing all the partial branch regexes so you'll need to also
130+
supply the "pragma: no branch" regex if you still want to use it.
131+
125132
``precision`` (integer): the number of digits after the decimal point to
126133
display for reported coverage percentages. The default is 0, displaying
127134
for example "87%". A value of 2 will display percentages like "87.32%".

doc/excluding.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Excluding code from coverage
77
:history: 20090613T090500, brand new docs.
88
:history: 20100224T200900, updated for 3.3.
99
:history: 20100725T211700, updated for 3.4.
10+
:history: 20110604T184400, updated for 3.5.
1011

1112

1213
You may have code in your project that you know won't be executed, and you want
@@ -76,7 +77,7 @@ all of them by adding a regex to the exclusion list::
7677
[report]
7778
exclude_lines = def __repr__
7879

79-
Here's a list of exclusions I've used::
80+
For example, here's a list of exclusions I've used::
8081

8182
[report]
8283
exclude_lines =
@@ -93,6 +94,9 @@ Note that when using the ``exclude_lines`` option in a configuration file, you
9394
are taking control of the entire list of regexes, so you need to re-specify the
9495
default "pragma: no cover" match if you still want it to apply.
9596

97+
A similar pragma, "no partial", can be used to tailor branch coverage
98+
measurement. See :ref:`branch` for details.
99+
96100

97101
Excluding source files
98102
----------------------

doc/index.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ coverage.py
1717
:history: 20100906T134700, updated for 3.4b2.
1818
:history: 20100919T163500, updated for 3.4 release.
1919
:history: 20110213T081200, claim true 3.2 compatibility.
20+
:history: 20110604T114800, update for 3.5b1
2021

2122
Coverage.py is a tool for measuring code coverage of Python programs. It
2223
monitors your program, noting which parts of the code have been executed, then
@@ -26,8 +27,8 @@ Coverage measurement is typically used to gauge the effectiveness of tests. It
2627
can show which parts of your code are being exercised by tests, and which are
2728
not.
2829

29-
The latest version is 3.4, released 19 September 2010.
30-
It is supported on Python 2.3 through 3.2.
30+
The latest version is 3.5b1, released ?? June 2011
31+
It is supported on Python versions 2.3 through 3.2.
3132

3233

3334
Quick start
@@ -39,7 +40,7 @@ Getting started is easy:
3940
or by using "easy_install coverage". For a few more details, see
4041
:ref:`install`.
4142

42-
#. Use ``coverage run`` to execute your program and gather data:
43+
#. Use ``coverage run`` to run your program and gather data:
4344

4445
.. code-block:: console
4546

0 commit comments

Comments
 (0)