diff options
-rw-r--r-- | coverage/data.py | 1 | ||||
-rw-r--r-- | coverage/html.py | 11 |
2 files changed, 9 insertions, 3 deletions
diff --git a/coverage/data.py b/coverage/data.py index 71d6624d..3d3647bb 100644 --- a/coverage/data.py +++ b/coverage/data.py @@ -3,6 +3,7 @@ """Coverage data for coverage.py.""" +import collections import glob import itertools import json 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, }) |