9
9
import sys
10
10
import os
11
11
import time
12
+ from typing import Any
12
13
13
- import py
14
14
import pytest
15
15
from execnet .gateway_base import dumps , DumpError
16
16
@@ -24,6 +24,29 @@ def setproctitle(title):
24
24
pass
25
25
26
26
27
+ class Producer :
28
+ """
29
+ Simplified implementation of the same interface as py.log, for backward compatibility
30
+ since we dropped the dependency on pylib.
31
+ Note: this is defined here because this module can't depend on xdist, so we need
32
+ to have the other way around.
33
+ """
34
+
35
+ def __init__ (self , name : str , * , enabled : bool = True ):
36
+ self .name = name
37
+ self .enabled = enabled
38
+
39
+ def __repr__ (self ) -> str :
40
+ return f"{ type (self ).__name__ } ({ self .name !r} , enabled={ self .enabled } )"
41
+
42
+ def __call__ (self , * a : Any , ** k : Any ) -> None :
43
+ if self .enabled :
44
+ print (f"[{ self .name } ]" , * a , ** k , file = sys .stderr )
45
+
46
+ def __getattr__ (self , name : str ) -> "Producer" :
47
+ return type (self )(name , enabled = self .enabled )
48
+
49
+
27
50
def worker_title (title ):
28
51
try :
29
52
setproctitle (title )
@@ -37,9 +60,7 @@ def __init__(self, config, channel):
37
60
self .config = config
38
61
self .workerid = config .workerinput .get ("workerid" , "?" )
39
62
self .testrunuid = config .workerinput ["testrunuid" ]
40
- self .log = py .log .Producer ("worker-%s" % self .workerid )
41
- if not config .option .debug :
42
- py .log .setconsumer (self .log ._keywords , None )
63
+ self .log = Producer (f"worker-{ self .workerid } " , enabled = config .option .debug )
43
64
self .channel = channel
44
65
config .pluginmanager .register (self )
45
66
0 commit comments