From 0ef160da9c07e1186f1f59f1490ff3160ffff97e Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Sat, 26 Jan 2019 09:50:34 -0500 Subject: Only compute contexts in HTML coverage when the option is specified. (For large coverage data sets, reporting the context can be expensive.) --- coverage/html.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'coverage/html.py') 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, }) -- cgit v1.2.1