From: Douglas Bagnall Date: Fri, 23 Feb 2024 03:24:11 +0000 (+1300) Subject: pytest:samba-tool: add a flag to print more in runcmd X-Git-Tag: tdb-1.4.11~1630 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1ab10b1fc19ac35ea1dcaf0161d59d394fc363c;p=thirdparty%2Fsamba.git pytest:samba-tool: add a flag to print more in runcmd Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/samba_tool/base.py b/python/samba/tests/samba_tool/base.py index a4f4578ff39..689ab11dde2 100644 --- a/python/samba/tests/samba_tool/base.py +++ b/python/samba/tests/samba_tool/base.py @@ -22,6 +22,7 @@ # These can all be accessed via os.environ["VARIABLENAME"] when needed import os +import sys import random import string from io import StringIO @@ -62,13 +63,28 @@ class SambaToolCmdTest(samba.tests.BlackboxTestCase): credentials=creds, lp=lp) @classmethod - def _run(cls, *argv): - """run a samba-tool command""" + def _run(cls, *argv, verbose=False): + """run a samba-tool command. + + positional arguments are effectively what gets passed to + bin/samba-tool. + + Add verbose=True during development to see the expanded + command and results. + """ cmd, args = cmd_sambatool()._resolve('samba-tool', *argv, outf=cls.stringIO(), errf=cls.stringIO()) result = cmd._run(*args) - return (result, cmd.outf.getvalue(), cmd.errf.getvalue()) + out = cmd.outf.getvalue() + err = cmd.errf.getvalue() + + if verbose: + print(f"bin/samba-tool {' '.join(argv)}\n\nstdout:\n" + f"{out}\n\nstderr:\n{err}\nresult: {result}\n", + file=sys.stderr) + + return (result, out, err) runcmd = _run runsubcmd = _run