12
12
import pprint
13
13
import reprlib
14
14
import sys
15
+ import types
15
16
import _thread
16
17
17
18
from coverage .misc import isolate_module
@@ -282,6 +283,7 @@ def __init__(self, outfile, show_process, filters):
282
283
self .write (f"New process: pid: { os .getpid ()!r} , parent pid: { os .getppid ()!r} \n " )
283
284
284
285
SYS_MOD_NAME = '$coverage.debug.DebugOutputFile.the_one'
286
+ SINGLETON_ATTR = 'the_one_and_is_interim'
285
287
286
288
@classmethod
287
289
def get_one (cls , fileobj = None , show_process = True , filters = (), interim = False ):
@@ -310,7 +312,8 @@ def get_one(cls, fileobj=None, show_process=True, filters=(), interim=False):
310
312
# this class can be defined more than once. But we really want
311
313
# a process-wide singleton. So stash it in sys.modules instead of
312
314
# on a class attribute. Yes, this is aggressively gross.
313
- the_one , is_interim = sys .modules .get (cls .SYS_MOD_NAME , (None , True ))
315
+ singleton_module = sys .modules .get (cls .SYS_MOD_NAME )
316
+ the_one , is_interim = getattr (singleton_module , cls .SINGLETON_ATTR , (None , True ))
314
317
if the_one is None or is_interim :
315
318
if fileobj is None :
316
319
debug_file_name = os .environ .get ("COVERAGE_DEBUG_FILE" , FORCED_DEBUG_FILE )
@@ -321,7 +324,9 @@ def get_one(cls, fileobj=None, show_process=True, filters=(), interim=False):
321
324
else :
322
325
fileobj = sys .stderr
323
326
the_one = cls (fileobj , show_process , filters )
324
- sys .modules [cls .SYS_MOD_NAME ] = (the_one , interim )
327
+ singleton_module = types .ModuleType (cls .SYS_MOD_NAME )
328
+ setattr (singleton_module , cls .SINGLETON_ATTR , (the_one , interim ))
329
+ sys .modules [cls .SYS_MOD_NAME ] = singleton_module
325
330
return the_one
326
331
327
332
def write (self , text ):
0 commit comments