Skip to content

Commit b0f5ac2

Browse files
committed
Documentation for static contexts
1 parent 2ae3ff2 commit b0f5ac2

File tree

6 files changed

+71
-3
lines changed

6 files changed

+71
-3
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ Change history for Coverage.py
1717
Unreleased
1818
----------
1919

20+
- Context support: static contexts let you specify a label for a coverage run,
21+
which is recorded in the data, and retained when you combine files. See
22+
:ref:`contexts` for more information. Currently, only static contexts are
23+
supported, with no reporting features.
24+
2025
- Environment variable substitution in configuration files now supports two
2126
syntaxes for controlling the behavior of undefined variables: if ``VARNAME``
2227
is not defined, ``${VARNAME?}`` will raise an error, and ``${VARNAME-default

README.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ library to determine which lines are executable, and which have been executed.
1919

2020
Coverage.py runs on many versions of Python:
2121

22-
* CPython 2.7 and 3.4 through 3.7.
22+
* CPython 2.7.
23+
* CPython 3.4 through 3.7.
2324
* PyPy2 6.0 and PyPy3 6.0.
2425
* Jython 2.7.1, though not for reporting.
2526
* IronPython 2.7.7, though not for reporting.
@@ -31,7 +32,8 @@ Documentation is on `Read the Docs`_. Code repository and issue tracker are on
3132
.. _GitHub: https://github.com/nedbat/coveragepy
3233

3334

34-
**New in 5.0:** SQLite data storage, dropped support for Python 2.6 and 3.3.
35+
**New in 5.0:** SQLite data storage, contexts, dropped support for Python 2.6
36+
and 3.3.
3537

3638
New in 4.5: Configurator plug-ins.
3739

doc/cmd.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ control, and can provide options that other invocation techniques (like test
6969
runner plugins) may not offer. See :ref:`config` for more details.
7070

7171

72-
.. _cmd_execution:
72+
.. _cmd_run:
7373

7474
Execution
7575
---------
@@ -118,6 +118,10 @@ configuration file for all options.
118118
.. _gevent: http://www.gevent.org/
119119
.. _eventlet: http://eventlet.net/
120120

121+
You can specify a :ref:`static context <contexts>` for a coverage run with
122+
``--context``. This can be any label you want, and will be recorded with the
123+
data. See :ref:`contexts` for more information.
124+
121125
By default, coverage.py does not measure code installed with the Python
122126
interpreter, for example, the standard library. If you want to measure that
123127
code as well as your own, add the ``-L`` (or ``--pylib``) flag.

doc/config.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ Before version 4.2, this option only accepted a single string.
132132

133133
.. versionadded:: 4.0
134134

135+
``context`` (string): the static context to record for this coverage run. See
136+
:ref:`contexts` for more information
137+
138+
.. versionadded:: 5.0
139+
135140
``data_file`` (string, default ".coverage"): the name of the data file to use
136141
for storing or reporting coverage. This value can include a path to another
137142
directory.

doc/contexts.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
.. Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
2+
.. For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
3+
4+
.. _contexts:
5+
6+
====================
7+
Measurement Contexts
8+
====================
9+
10+
.. :history: 20180921T085400, new for 5.0
11+
12+
.. versionadded:: 5.0
13+
14+
Coverage.py measures whether code was run, but it can also record the context
15+
in which it was run. This can provide more information to help you understand
16+
the behavior of your tests.
17+
18+
There are two kinds of context: static and dynamic. Static contexts are fixed
19+
for an entire run, and are set explicitly with an option.
20+
21+
Dynamic contexts are coming soon.
22+
23+
24+
Static contexts
25+
---------------
26+
27+
A static context is set by an option when you run coverage.py. The value is
28+
fixed for the duration of a run. They can be any text you like, for example,
29+
"python3" or "with_numpy". The context is recorded with the data.
30+
31+
When you :ref:`combine multiple data files <cmd_combining>` together, they can
32+
have differing contexts. All of the information is retained, so that the
33+
different contexts are correctly recorded in the combined file.
34+
35+
A static context is specified with the ``--context=CONTEXT`` option to
36+
:ref:`coverage run <cmd_run>`.
37+
38+
39+
Dynamic contexts
40+
----------------
41+
42+
Not implemented yet.
43+
44+
45+
Context reporting
46+
-----------------
47+
48+
There is currently no support for using contexts during reporting. I'm
49+
interested to `hear your ideas`__ for what would be useful.
50+
51+
__ https://nedbatchelder.com/site/aboutned.html

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ More information
206206
excluding
207207
branch
208208
subprocess
209+
contexts
209210
api
210211
howitworks
211212
plugins

0 commit comments

Comments
 (0)