Skip to content

Commit 3cb320a

Browse files
committed
WIP: enable live logging for non-parallel test runs
This provides incremental output when test is running _without xdist_, just like the old runner did. With xdist the live output is not available, I believe because of pytest-dev/pytest-xdist#402 pytest-dev/pytest-xdist#883 might help with that, but I'm not going to hold my breath until it is available on distros we use.
1 parent 915b0c5 commit 3cb320a

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

bin/tests/system/conftest.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -364,28 +364,25 @@ def _run_script( # pylint: disable=too-many-arguments
364364
raise FileNotFoundError(f"script {script} not found in {cwd}")
365365
logger.debug("running script: %s %s %s", interpreter, script, " ".join(args))
366366
logger.debug(" workdir: %s", cwd)
367-
stdout = b""
368367
returncode = 1
369-
try:
370-
proc = subprocess.run(
371-
[interpreter, script] + args,
372-
env=env,
373-
check=True,
374-
stdout=subprocess.PIPE,
375-
stderr=subprocess.STDOUT,
376-
)
377-
except subprocess.CalledProcessError as exc:
378-
stdout = exc.stdout
379-
returncode = exc.returncode
380-
raise exc
381-
else:
382-
stdout = proc.stdout
383-
returncode = proc.returncode
384-
finally:
385-
if stdout:
386-
for line in stdout.decode().splitlines():
387-
logger.debug(" %s", line)
388-
logger.debug(" exited with %d", returncode)
368+
369+
cmd = [interpreter, script] + args
370+
proc = subprocess.Popen(
371+
cmd,
372+
env=env,
373+
stdout=subprocess.PIPE,
374+
stderr=subprocess.STDOUT,
375+
bufsize=1,
376+
universal_newlines=True
377+
)
378+
if proc.stdout:
379+
for line in proc.stdout:
380+
logger.info(" %s", line.rstrip('\n'))
381+
proc.communicate()
382+
returncode = proc.returncode
383+
if returncode:
384+
raise subprocess.CalledProcessError(returncode, cmd)
385+
logger.debug(" exited with %d", returncode)
389386
return proc
390387

391388
@pytest.fixture(scope="module")

0 commit comments

Comments
 (0)