@@ -330,9 +330,10 @@ def write_results(self, show_missing=True, summary=False, coverdir=None):
330330
331331 source = linecache .getlines (filename )
332332 coverpath = os .path .join (dir , modulename + ".cover" )
333+ with open (filename , 'rb' ) as fp :
334+ encoding , _ = tokenize .detect_encoding (fp .readline )
333335 n_hits , n_lines = self .write_results_file (coverpath , source ,
334- lnotab , count )
335-
336+ lnotab , count , encoding )
336337 if summary and n_lines :
337338 percent = int (100 * n_hits / n_lines )
338339 sums [modulename ] = n_lines , percent , modulename , filename
@@ -351,11 +352,11 @@ def write_results(self, show_missing=True, summary=False, coverdir=None):
351352 except IOError as err :
352353 print ("Can't save counts files because %s" % err , file = sys .stderr )
353354
354- def write_results_file (self , path , lines , lnotab , lines_hit ):
355+ def write_results_file (self , path , lines , lnotab , lines_hit , encoding = None ):
355356 """Return a coverage results file in path."""
356357
357358 try :
358- outfile = open (path , "w" )
359+ outfile = open (path , "w" , encoding = encoding )
359360 except IOError as err :
360361 print (("trace: Could not open %r for writing: %s"
361362 "- skipping" % (path , err )), file = sys .stderr )
0 commit comments