diff --git a/mypy/waiter.py b/mypy/waiter.py index f0c7de6002a6..e8ba99d4efd8 100644 --- a/mypy/waiter.py +++ b/mypy/waiter.py @@ -9,7 +9,7 @@ from multiprocessing import cpu_count import pipes import re -from subprocess import Popen, STDOUT +from subprocess import Popen, STDOUT, DEVNULL import sys import tempfile import time @@ -25,20 +25,22 @@ class LazySubprocess: """Wrapper around a subprocess that runs a test task.""" def __init__(self, name: str, args: List[str], *, cwd: str = None, - env: Dict[str, str] = None, passthrough: bool = False) -> None: + env: Dict[str, str] = None, passthrough: Optional[int] = None) -> None: self.name = name self.args = args self.cwd = cwd self.env = env self.start_time = None # type: float self.end_time = None # type: float + # None means no passthrough + # otherwise, it represents verbosity level self.passthrough = passthrough def start(self) -> None: - if self.passthrough: - self.outfile = None - else: + if self.passthrough is None or self.passthrough < 0: self.outfile = tempfile.TemporaryFile() + else: + self.outfile = None self.start_time = time.perf_counter() self.process = Popen(self.args, cwd=self.cwd, env=self.env, stdout=self.outfile, stderr=STDOUT) @@ -51,7 +53,7 @@ def status(self) -> Optional[int]: return self.process.returncode def read_output(self) -> str: - if self.passthrough: + if not self.outfile: return '' file = self.outfile file.seek(0) diff --git a/runtests.py b/runtests.py index 3371f9ae8b91..7d6206ca0652 100755 --- a/runtests.py +++ b/runtests.py @@ -111,7 +111,7 @@ def add_pytest(self, name: str, pytest_args: List[str], coverage: bool = False) else: args = [sys.executable, '-m', 'pytest'] + pytest_args - self.waiter.add(LazySubprocess(full_name, args, env=self.env, passthrough=True), + self.waiter.add(LazySubprocess(full_name, args, env=self.env, passthrough=self.verbosity), sequential=True) def add_python(self, name: str, *args: str, cwd: Optional[str] = None) -> None: @@ -422,6 +422,13 @@ def main() -> None: pyt_arglist.append('--lf') if ff: pyt_arglist.append('--ff') + if verbosity >= 1: + pyt_arglist.extend(['-v'] * verbosity) + elif verbosity < 0: + pyt_arglist.extend(['-q'] * (-verbosity)) + if parallel_limit: + if '-n' not in pyt_arglist: + pyt_arglist.append('-n{}'.format(parallel_limit)) driver = Driver(whitelist=whitelist, blacklist=blacklist, lf=lf, ff=ff, arglist=arglist, pyt_arglist=pyt_arglist, verbosity=verbosity,