9
9
from multiprocessing import cpu_count
10
10
import pipes
11
11
import re
12
- from subprocess import Popen , STDOUT
12
+ from subprocess import Popen , STDOUT , DEVNULL
13
13
import sys
14
14
import tempfile
15
15
import time
@@ -25,20 +25,25 @@ class LazySubprocess:
25
25
"""Wrapper around a subprocess that runs a test task."""
26
26
27
27
def __init__ (self , name : str , args : List [str ], * , cwd : str = None ,
28
- env : Dict [str , str ] = None , passthrough : bool = False ) -> None :
28
+ env : Dict [str , str ] = None , passthrough : Optional [ int ] = None ) -> None :
29
29
self .name = name
30
30
self .args = args
31
31
self .cwd = cwd
32
32
self .env = env
33
33
self .start_time = None # type: float
34
34
self .end_time = None # type: float
35
+ # None means no passthrough
36
+ # otherwise, it represents verbosity level
35
37
self .passthrough = passthrough
36
38
37
39
def start (self ) -> None :
38
- if self .passthrough :
39
- self .outfile = None
40
- else :
40
+ if self .passthrough is None :
41
41
self .outfile = tempfile .TemporaryFile ()
42
+ else :
43
+ if self .passthrough >= 0 :
44
+ self .outfile = None
45
+ else :
46
+ self .outfile = DEVNULL
42
47
self .start_time = time .perf_counter ()
43
48
self .process = Popen (self .args , cwd = self .cwd , env = self .env ,
44
49
stdout = self .outfile , stderr = STDOUT )
@@ -51,7 +56,7 @@ def status(self) -> Optional[int]:
51
56
return self .process .returncode
52
57
53
58
def read_output (self ) -> str :
54
- if self .passthrough :
59
+ if self .passthrough is not None :
55
60
return ''
56
61
file = self .outfile
57
62
file .seek (0 )
0 commit comments