mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
Enable live logging for non-parallel pytest 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 https://github.com/pytest-dev/pytest-xdist/issues/402 https://github.com/pytest-dev/pytest-xdist/pull/883 might help with that, but I'm not going to hold my breath until it is available on distros we use.
This commit is contained in:
@@ -90,6 +90,21 @@ if os.getenv("LEGACY_TEST_RUNNER", "0") == "0":
|
|||||||
|
|
||||||
# ---------------------- Module initialization ---------------------------
|
# ---------------------- Module initialization ---------------------------
|
||||||
|
|
||||||
|
def avoid_duplicated_logs():
|
||||||
|
"""
|
||||||
|
Remove direct root logger output to file descriptors.
|
||||||
|
This default is causing duplicates because all our messages go through
|
||||||
|
regular logging as well and are thus displayed twice.
|
||||||
|
"""
|
||||||
|
todel = []
|
||||||
|
for handler in logging.root.handlers:
|
||||||
|
if handler.__class__ == logging.StreamHandler:
|
||||||
|
# Beware: As for pytest 7.2.2, LiveLogging and LogCapture
|
||||||
|
# handlers inherit from logging.StreamHandler
|
||||||
|
todel.append(handler)
|
||||||
|
for handler in todel:
|
||||||
|
logging.root.handlers.remove(handler)
|
||||||
|
|
||||||
def parse_env(env_text):
|
def parse_env(env_text):
|
||||||
"""Parse the POSIX env format into Python dictionary."""
|
"""Parse the POSIX env format into Python dictionary."""
|
||||||
out = {}
|
out = {}
|
||||||
@@ -283,6 +298,7 @@ if os.getenv("LEGACY_TEST_RUNNER", "0") == "0":
|
|||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def logger(system_test_name):
|
def logger(system_test_name):
|
||||||
"""Logging facility specific to this test."""
|
"""Logging facility specific to this test."""
|
||||||
|
avoid_duplicated_logs()
|
||||||
return logging.getLogger(system_test_name)
|
return logging.getLogger(system_test_name)
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
@@ -378,29 +394,26 @@ if os.getenv("LEGACY_TEST_RUNNER", "0") == "0":
|
|||||||
raise FileNotFoundError(f"script {script} not found in {cwd}")
|
raise FileNotFoundError(f"script {script} not found in {cwd}")
|
||||||
logger.debug("running script: %s %s %s", interpreter, script, " ".join(args))
|
logger.debug("running script: %s %s %s", interpreter, script, " ".join(args))
|
||||||
logger.debug(" workdir: %s", cwd)
|
logger.debug(" workdir: %s", cwd)
|
||||||
stdout = b""
|
|
||||||
returncode = 1
|
returncode = 1
|
||||||
try:
|
|
||||||
proc = subprocess.run(
|
cmd = [interpreter, script] + args
|
||||||
[interpreter, script] + args,
|
with subprocess.Popen(
|
||||||
env=env,
|
cmd,
|
||||||
check=True,
|
env=env,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
)
|
bufsize=1,
|
||||||
except subprocess.CalledProcessError as exc:
|
universal_newlines=True,
|
||||||
stdout = exc.stdout
|
errors="backslashreplace",
|
||||||
returncode = exc.returncode
|
) as proc:
|
||||||
raise exc
|
if proc.stdout:
|
||||||
else:
|
for line in proc.stdout:
|
||||||
stdout = proc.stdout
|
logger.info(" %s", line.rstrip("\n"))
|
||||||
|
proc.communicate()
|
||||||
returncode = proc.returncode
|
returncode = proc.returncode
|
||||||
finally:
|
if returncode:
|
||||||
if stdout:
|
raise subprocess.CalledProcessError(returncode, cmd)
|
||||||
for line in stdout.decode().splitlines():
|
|
||||||
logger.debug(" %s", line)
|
|
||||||
logger.debug(" exited with %d", returncode)
|
logger.debug(" exited with %d", returncode)
|
||||||
return proc
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def shell(env, system_test_dir, logger):
|
def shell(env, system_test_dir, logger):
|
||||||
|
Reference in New Issue
Block a user