22
33import argparse
44import contextlib
5- import copy
65import functools
76import os
87import random
@@ -31,16 +30,6 @@ def write(v):
3130 pass
3231
3332
34- @contextlib .contextmanager
35- def _backup (obj , attr ):
36- backup = getattr (obj , attr )
37- try :
38- setattr (obj , attr , copy .copy (backup ))
39- yield
40- finally :
41- setattr (obj , attr , backup )
42-
43-
4433def _ensure_topdir (meth ):
4534 @functools .wraps (meth )
4635 def ensure_topdir_wrapper (self , * args , ** kwargs ):
@@ -151,8 +140,7 @@ def sep(self, stream, s, txt):
151140 def summary (self , stream ):
152141 """Produce coverage reports."""
153142
154- with _backup (self .cov , 'config' ):
155- total = self .cov .report (ignore_errors = True , output_format = 'total' , precision = self .cov_precision , file = _NullFile )
143+ total = self .cov .report (ignore_errors = True , output_format = 'total' , precision = self .cov_precision , file = _NullFile )
156144
157145 # Output coverage section header.
158146 if len (self .node_descs ) == 1 :
@@ -179,20 +167,17 @@ def summary(self, stream):
179167 }
180168 skip_covered = isinstance (self .cov_report , dict ) and 'skip-covered' in self .cov_report .values ()
181169 options .update ({'skip_covered' : skip_covered or None })
182- with _backup (self .cov , 'config' ):
183- self .cov .report (** options )
170+ self .cov .report (** options )
184171
185172 # Produce annotated source code report if wanted.
186173 if 'annotate' in self .cov_report :
187174 annotate_dir = self .cov_report ['annotate' ]
188175
189- with _backup (self .cov , 'config' ):
190- self .cov .annotate (ignore_errors = True , directory = annotate_dir )
176+ self .cov .annotate (ignore_errors = True , directory = annotate_dir )
191177 # We need to call Coverage.report here, just to get the total
192178 # Coverage.annotate don't return any total and we need it for --cov-fail-under.
193179
194- with _backup (self .cov , 'config' ):
195- self .cov .report (ignore_errors = True , file = _NullFile )
180+ self .cov .report (ignore_errors = True , file = _NullFile )
196181 if annotate_dir :
197182 stream .write (f'Coverage annotated source written to dir { annotate_dir } \n ' )
198183 else :
@@ -201,49 +186,43 @@ def summary(self, stream):
201186 # Produce html report if wanted.
202187 if 'html' in self .cov_report :
203188 output = self .cov_report ['html' ]
204- with _backup (self .cov , 'config' ):
205- self .cov .html_report (ignore_errors = True , directory = output )
189+ self .cov .html_report (ignore_errors = True , directory = output )
206190 stream .write (f'Coverage HTML written to dir { self .cov .config .html_dir if output is None else output } \n ' )
207191
208192 # Produce xml report if wanted.
209193 if 'xml' in self .cov_report :
210194 output = self .cov_report ['xml' ]
211- with _backup (self .cov , 'config' ):
212- self .cov .xml_report (ignore_errors = True , outfile = output )
195+ self .cov .xml_report (ignore_errors = True , outfile = output )
213196 stream .write (f'Coverage XML written to file { self .cov .config .xml_output if output is None else output } \n ' )
214197
215198 # Produce json report if wanted
216199 if 'json' in self .cov_report :
217200 output = self .cov_report ['json' ]
218- with _backup (self .cov , 'config' ):
219- self .cov .json_report (ignore_errors = True , outfile = output )
201+ self .cov .json_report (ignore_errors = True , outfile = output )
220202 stream .write ('Coverage JSON written to file %s\n ' % (self .cov .config .json_output if output is None else output ))
221203
222204 # Produce Markdown report if wanted.
223205 if 'markdown' in self .cov_report :
224206 output = self .cov_report ['markdown' ]
225- with _backup (self .cov , 'config' ):
226- with Path (output ).open ('w' ) as output_file :
227- self .cov .report (ignore_errors = True , file = output_file , output_format = 'markdown' )
207+ with Path (output ).open ('w' ) as output_file :
208+ self .cov .report (ignore_errors = True , file = output_file , output_format = 'markdown' )
228209 stream .write (f'Coverage Markdown information written to file { output } \n ' )
229210
230211 # Produce Markdown report if wanted, appending to output file
231212 if 'markdown-append' in self .cov_report :
232213 output = self .cov_report ['markdown-append' ]
233- with _backup (self .cov , 'config' ):
234- with Path (output ).open ('a' ) as output_file :
235- self .cov .report (ignore_errors = True , file = output_file , output_format = 'markdown' )
214+ with Path (output ).open ('a' ) as output_file :
215+ self .cov .report (ignore_errors = True , file = output_file , output_format = 'markdown' )
236216 stream .write (f'Coverage Markdown information appended to file { output } \n ' )
237217
238218 # Produce lcov report if wanted.
239219 if 'lcov' in self .cov_report :
240220 output = self .cov_report ['lcov' ]
241- with _backup (self .cov , 'config' ):
242- self .cov .lcov_report (ignore_errors = True , outfile = output )
221+ self .cov .lcov_report (ignore_errors = True , outfile = output )
243222
244- # We need to call Coverage.report here, just to get the total
245- # Coverage.lcov_report doesn't return any total and we need it for --cov-fail-under.
246- self .cov .report (ignore_errors = True , file = _NullFile )
223+ # We need to call Coverage.report here, just to get the total
224+ # Coverage.lcov_report doesn't return any total and we need it for --cov-fail-under.
225+ self .cov .report (ignore_errors = True , file = _NullFile )
247226
248227 stream .write (f'Coverage LCOV written to file { self .cov .config .lcov_output if output is None else output } \n ' )
249228
0 commit comments