diff options
author | Stephan Richter <stephan.richter@gmail.com> | 2019-01-26 09:50:34 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2019-06-10 17:15:32 -0400 |
commit | 0ef160da9c07e1186f1f59f1490ff3160ffff97e (patch) | |
tree | 7a6f668299ce241bca994fe24048f1762af32f07 /coverage/html.py | |
parent | 6e0f7bae413234f50b2cc3eb618185f4f8bf82ef (diff) | |
download | python-coveragepy-git-0ef160da9c07e1186f1f59f1490ff3160ffff97e.tar.gz |
Only compute contexts in HTML coverage when the option is specified. (For large coverage data sets, reporting the context can be expensive.)
Diffstat (limited to 'coverage/html.py')
-rw-r--r-- | coverage/html.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/coverage/html.py b/coverage/html.py index 3cd47d5a..f7dbeba4 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -3,6 +3,7 @@ """HTML reporting for coverage.py.""" +import collections import datetime import json import os @@ -214,8 +215,10 @@ class HtmlReporter(Reporter): c_mis = "mis" c_par = "par " + c_run - # Lookup line number contexts. - contexts_by_lineno = analysis.data.contexts_by_lineno(fr.filename) + contexts_by_lineno = collections.defaultdict(list) + if self.config.show_contexts: + # Lookup line number contexts. + contexts_by_lineno = analysis.data.contexts_by_lineno(fr.filename) lines = [] @@ -271,7 +274,9 @@ class HtmlReporter(Reporter): 'html': ''.join(html), 'number': lineno, 'class': ' '.join(line_class) or "pln", - 'contexts': sorted(filter(None, contexts_by_lineno[lineno])) or None, + 'contexts': \ + (sorted(filter(None, contexts_by_lineno[lineno])) or None) + if self.config.show_contexts else None, 'annotate': annotate_html, 'annotate_long': annotate_long, }) |