Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: third_party/coverage-3.6/doc/excluding.rst

Issue 14988009: First cut of testing infrastructure for recipes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: nitfixen Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/coverage-3.6/doc/contributing.rst ('k') | third_party/coverage-3.6/doc/faq.rst » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/coverage-3.6/doc/excluding.rst
diff --git a/third_party/coverage-3.6/doc/excluding.rst b/third_party/coverage-3.6/doc/excluding.rst
new file mode 100644
index 0000000000000000000000000000000000000000..f1262c35fcfc42fbc291884c1c503aac8f78069c
--- /dev/null
+++ b/third_party/coverage-3.6/doc/excluding.rst
@@ -0,0 +1,105 @@
+.. _excluding:
+
+============================
+Excluding code from coverage
+============================
+
+:history: 20090613T090500, brand new docs.
+:history: 20100224T200900, updated for 3.3.
+:history: 20100725T211700, updated for 3.4.
+:history: 20110604T184400, updated for 3.5.
+
+
+You may have code in your project that you know won't be executed, and you want
+to tell coverage to ignore it. For example, you may have debugging-only code
+that won't be executed during your unit tests. You can tell coverage to exclude
+this code during reporting so that it doesn't clutter your reports with noise
+about code that you don't need to hear about.
+
+Coverage will look for comments marking clauses for exclusion. In this code,
+the "if debug" clause is excluded from reporting::
+
+ a = my_function1()
+ if debug: # pragma: no cover
+ msg = "blah blah"
+ log_message(msg, a)
+ b = my_function2()
+
+Any line with a comment of "pragma: no cover" is excluded. If that line
+introduces a clause, for example, an if clause, or a function or class
+definition, then the entire clause is also excluded. Here the __repr__
+function is not reported as missing::
+
+ class MyObject(object):
+ def __init__(self):
+ blah1()
+ blah2()
+
+ def __repr__(self): # pragma: no cover
+ return "<MyObject>"
+
+Excluded code is executed as usual, and its execution is recorded in the
+coverage data as usual. When producing reports though, coverage excludes it from
+the list of missing code.
+
+
+Branch coverage
+---------------
+
+When measuring :ref:`branch coverage <branch>`, a condtional will not be
+counted as a branch if one of its choices is excluded::
+
+ def only_one_choice(x):
+ if x:
+ blah1()
+ blah2()
+ else: # pragma: no cover
+ # x is always true.
+ blah3()
+
+Because the ``else`` clause is excluded, the ``if`` only has one possible
+next line, so it isn't considered a branch at all.
+
+
+Advanced exclusion
+------------------
+
+Coverage identifies exclusions by matching lines against a list of regular
+expressions. Using :ref:`configuration files <config>` or the coverage
+:ref:`API <api>`, you can add to that list. This is useful if you have
+often-used constructs to exclude that can be matched with a regex. You can
+exclude them all at once without littering your code with exclusion pragmas.
+
+For example, you might decide that __repr__ functions are usually only used
+in debugging code, and are uninteresting to test themselves. You could exclude
+all of them by adding a regex to the exclusion list::
+
+ [report]
+ exclude_lines = def __repr__
+
+For example, here's a list of exclusions I've used::
+
+ [report]
+ exclude_lines =
+ pragma: no cover
+ def __repr__
+ if self.debug:
+ if settings.DEBUG
+ raise AssertionError
+ raise NotImplementedError
+ if 0:
+ if __name__ == .__main__.:
+
+Note that when using the ``exclude_lines`` option in a configuration file, you
+are taking control of the entire list of regexes, so you need to re-specify the
+default "pragma: no cover" match if you still want it to apply.
+
+A similar pragma, "no branch", can be used to tailor branch coverage
+measurement. See :ref:`branch` for details.
+
+
+Excluding source files
+----------------------
+
+See :ref:`source` for ways to limit what files coverage.py measures or reports
+on.
« no previous file with comments | « third_party/coverage-3.6/doc/contributing.rst ('k') | third_party/coverage-3.6/doc/faq.rst » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698