]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pytest:samba-tool: add a flag to print more in runcmd
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 23 Feb 2024 03:24:11 +0000 (16:24 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 1 Mar 2024 00:19:45 +0000 (00:19 +0000)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/samba_tool/base.py

index a4f4578ff392454bd98aef4e3765f32ec1c1ef90..689ab11dde27fb2d1340a1e6e7f50410c0029493 100644 (file)
@@ -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