From de1a53b135b7ff92b3be0a455b2bd5504aead62a Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 10 Mar 2026 17:49:48 +0100 Subject: [PATCH] fix: separate stderr capture in incus and suppress in test plugin Capture stderr separately in Incus.run() instead of merging it into stdout, which corrupted JSON parsing in run_json(). Add --quiet flag to reduce incus noise. Suppress stderr in Remote subprocess to prevent pytest-xdist communication issues. --- cmdeploy/src/cmdeploy/lxc/incus.py | 12 +++++++----- cmdeploy/src/cmdeploy/tests/plugin.py | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cmdeploy/src/cmdeploy/lxc/incus.py b/cmdeploy/src/cmdeploy/lxc/incus.py index 371768be..54b6dfe6 100644 --- a/cmdeploy/src/cmdeploy/lxc/incus.py +++ b/cmdeploy/src/cmdeploy/lxc/incus.py @@ -122,7 +122,7 @@ class Incus: to the terminal line-by-line while also being captured for later return via result.stdout. """ - cmd = ["incus"] + list(args) + cmd = ["incus", "--quiet"] + list(args) sub = self.out.new_prefixed_out(" ") if not capture: @@ -146,7 +146,7 @@ class Incus: text=True, stdin=subprocess.PIPE if input else subprocess.DEVNULL, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, + stderr=subprocess.PIPE, ) stdout_lines = [] @@ -159,15 +159,17 @@ class Incus: if sub.verbosity >= 2: sub.print(f" > {line.rstrip()}") + stderr = proc.stderr.read() ret = proc.wait() stdout = "".join(stdout_lines) if check and ret != 0: - for line in stdout.splitlines(): + full_output = stdout + stderr + for line in full_output.splitlines(): if sub.verbosity < 1: # and we haven't printed it yet sub.red(line) - raise subprocess.CalledProcessError(ret, cmd, output=stdout) + raise subprocess.CalledProcessError(ret, cmd, output=stdout, stderr=stderr) - return subprocess.CompletedProcess(cmd, ret, stdout=stdout) + return subprocess.CompletedProcess(cmd, ret, stdout=stdout, stderr=stderr) def run_json(self, args, check=True): """Run an incus command with ``--format=json``. diff --git a/cmdeploy/src/cmdeploy/tests/plugin.py b/cmdeploy/src/cmdeploy/tests/plugin.py index 8e8bf2d6..50ff905b 100644 --- a/cmdeploy/src/cmdeploy/tests/plugin.py +++ b/cmdeploy/src/cmdeploy/tests/plugin.py @@ -516,6 +516,7 @@ class Remote: command, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, ) self._procs.append(popen) while 1: