All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: eesposit@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com,
	qemu-block@nongnu.org, mreitz@redhat.com
Subject: [PATCH v2 2/5] qemu-iotests: allow passing unittest.main arguments to the test scripts
Date: Tue, 23 Mar 2021 19:19:24 +0100	[thread overview]
Message-ID: <20210323181928.311862-3-pbonzini@redhat.com> (raw)
In-Reply-To: <20210323181928.311862-1-pbonzini@redhat.com>

Python test scripts that use unittest consist of multiple tests.
unittest.main allows selecting which tests to run, but currently this
is not possible because the iotests wrapper ignores sys.argv.

unittest.main command line options also allow the user to pick the
desired options for verbosity, failfast mode, etc.  While "-d" is
currently translated to "-v", it also enables extra debug output,
and other options are not available at all.

These command line options only work if the unittest.main testRunner
argument is a type, rather than a TestRunner instance.  Therefore, pass
the class name and "verbosity" argument to unittest.main, and adjust for
the different default warnings between TextTestRunner and unittest.main.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/qemu-iotests/iotests.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 0521235030..c7915684ba 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -1308,12 +1308,16 @@ def __init__(self, stream: Optional[io.TextIOBase] = None,
                          resultclass=resultclass,
                          *args, **kwargs)
 
-def execute_unittest(debug=False):
+def execute_unittest(argv: List[str], debug: bool= False):
     """Executes unittests within the calling module."""
 
-    verbosity = 2 if debug else 1
-    runner = unittest.ReproducibleTestRunner(verbosity=verbosity)
-    unittest.main(testRunner=runner)
+    # Some tests have warnings, especially ResourceWarnings for unclosed
+    # files and sockets.  Ignore them for now to ensure reproducibility of
+    # the test output.
+    unittest.main(argv=argv,
+                  testRunner=ReproducibleTestRunner,
+                  verbosity=2 if debug else 1,
+                  warnings=None if sys.warnoptions else 'ignore')
 
 def execute_setup_common(supported_fmts: Sequence[str] = (),
                          supported_platforms: Sequence[str] = (),
@@ -1350,7 +1354,7 @@ def execute_test(*args, test_function=None, **kwargs):
 
     debug = execute_setup_common(*args, **kwargs)
     if not test_function:
-        execute_unittest(debug)
+        execute_unittest(sys.argv, debug)
     else:
         test_function()
 
-- 
2.30.1




  parent reply	other threads:[~2021-03-23 19:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23 18:19 [PATCH v2 0/5] qemu-iotests: quality of life improvements Paolo Bonzini
2021-03-23 18:19 ` [PATCH v2 1/5] qemu-iotests: do not buffer the test output Paolo Bonzini
2021-03-23 18:54   ` Vladimir Sementsov-Ogievskiy
2021-03-23 18:57     ` Vladimir Sementsov-Ogievskiy
2021-03-23 18:19 ` Paolo Bonzini [this message]
2021-03-23 19:02   ` [PATCH v2 2/5] qemu-iotests: allow passing unittest.main arguments to the test scripts Vladimir Sementsov-Ogievskiy
2021-03-23 19:17   ` Vladimir Sementsov-Ogievskiy
2021-03-23 21:22     ` Paolo Bonzini
2021-03-24  7:34       ` Vladimir Sementsov-Ogievskiy
2021-03-23 18:19 ` [PATCH v2 3/5] qemu-iotests: move command line and environment handling from TestRunner to TestEnv Paolo Bonzini
2021-03-23 18:19 ` [PATCH v2 4/5] qemu-iotests: let "check" spawn an arbitrary test command Paolo Bonzini
2021-03-23 19:12   ` Vladimir Sementsov-Ogievskiy
2021-03-23 21:20     ` Paolo Bonzini
2021-03-24  7:36       ` Vladimir Sementsov-Ogievskiy
2021-03-23 18:19 ` [PATCH v2 5/5] qemu-iotests: fix case of SOCK_DIR already in the environment Paolo Bonzini
2021-03-24 15:17 ` [PATCH v2 0/5] qemu-iotests: quality of life improvements Emanuele Giuseppe Esposito
2021-03-25 18:15 ` Max Reitz
2021-03-26  6:50   ` Paolo Bonzini
2021-03-26 13:40 ` Max Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210323181928.311862-3-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=eesposit@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.