[Qemu-devel] [PATCH v2 3/5] iotests: Allow skipping test cases

Max Reitz posted 5 patches 6 years, 7 months ago
There is a newer version of this series
[Qemu-devel] [PATCH v2 3/5] iotests: Allow skipping test cases
Posted by Max Reitz 6 years, 7 months ago
case_notrun() does not actually skip the current test case.  It just
adds a "notrun" note and then returns to the caller, who manually has to
skip the test.  Generally, skipping a test case is as simple as
returning from the current function, but not always: For example, this
model does not allow skipping tests already in the setUp() function.

Thus, add a QMPTestCase.case_skip() function that invokes case_notrun()
and then self.skipTest().  To make this work, we need to filter the
information on how many test cases were skipped from the unittest
output.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 tests/qemu-iotests/iotests.py | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 3ecef5bc90..1b0ac50153 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -741,6 +741,11 @@ class QMPTestCase(unittest.TestCase):
             return self.pause_wait(job_id)
         return result
 
+    def case_skip(self, reason):
+        '''Skip this test case'''
+        case_notrun(reason)
+        self.skipTest(reason)
+
 
 def notrun(reason):
     '''Skip this test suite'''
@@ -752,7 +757,10 @@ def notrun(reason):
     sys.exit(0)
 
 def case_notrun(reason):
-    '''Skip this test case'''
+    '''Mark this test case as not having been run, but do not actually
+    skip it; that is left to the caller.  See QMPTestCase.case_skip()
+    for a variant that actually skips the current test case.'''
+
     # Each test in qemu-iotests has a number ("seq")
     seq = os.path.basename(sys.argv[0])
 
@@ -879,4 +887,12 @@ def main(supported_fmts=[], supported_oses=['linux'], supported_cache_modes=[],
         unittest.main(testRunner=MyTestRunner)
     finally:
         if not debug:
-            sys.stderr.write(re.sub(r'Ran (\d+) tests? in [\d.]+s', r'Ran \1 tests', output.getvalue()))
+            out = output.getvalue()
+            out = re.sub(r'Ran (\d+) tests? in [\d.]+s', r'Ran \1 tests', out)
+
+            # Hide skipped tests from the reference output
+            out = re.sub(r'OK \(skipped=\d+\)', 'OK', out)
+            out_first_line, out_rest = out.split('\n', 1)
+            out = out_first_line.replace('s', '.') + '\n' + out_rest
+
+            sys.stderr.write(out)
-- 
2.21.0


Re: [Qemu-devel] [Qemu-block] [PATCH v2 3/5] iotests: Allow skipping test cases
Posted by John Snow 6 years, 6 months ago

On 6/25/19 5:19 PM, Max Reitz wrote:
> case_notrun() does not actually skip the current test case.  It just
> adds a "notrun" note and then returns to the caller, who manually has to
> skip the test.  Generally, skipping a test case is as simple as
> returning from the current function, but not always: For example, this
> model does not allow skipping tests already in the setUp() function.
> 
> Thus, add a QMPTestCase.case_skip() function that invokes case_notrun()
> and then self.skipTest().  To make this work, we need to filter the
> information on how many test cases were skipped from the unittest
> output.
> 

I feel like skipping sub-tests has been a point of contention before,
but I don't recall the outcome.

Cleber, can you help jog my memory?

> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  tests/qemu-iotests/iotests.py | 20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index 3ecef5bc90..1b0ac50153 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -741,6 +741,11 @@ class QMPTestCase(unittest.TestCase):
>              return self.pause_wait(job_id)
>          return result
>  
> +    def case_skip(self, reason):
> +        '''Skip this test case'''
> +        case_notrun(reason)
> +        self.skipTest(reason)
> +
>  
>  def notrun(reason):
>      '''Skip this test suite'''
> @@ -752,7 +757,10 @@ def notrun(reason):
>      sys.exit(0)
>  
>  def case_notrun(reason):
> -    '''Skip this test case'''
> +    '''Mark this test case as not having been run, but do not actually
> +    skip it; that is left to the caller.  See QMPTestCase.case_skip()
> +    for a variant that actually skips the current test case.'''
> +
>      # Each test in qemu-iotests has a number ("seq")
>      seq = os.path.basename(sys.argv[0])
>  
> @@ -879,4 +887,12 @@ def main(supported_fmts=[], supported_oses=['linux'], supported_cache_modes=[],
>          unittest.main(testRunner=MyTestRunner)
>      finally:
>          if not debug:
> -            sys.stderr.write(re.sub(r'Ran (\d+) tests? in [\d.]+s', r'Ran \1 tests', output.getvalue()))
> +            out = output.getvalue()
> +            out = re.sub(r'Ran (\d+) tests? in [\d.]+s', r'Ran \1 tests', out)
> +
> +            # Hide skipped tests from the reference output
> +            out = re.sub(r'OK \(skipped=\d+\)', 'OK', out)
> +            out_first_line, out_rest = out.split('\n', 1)
> +            out = out_first_line.replace('s', '.') + '\n' + out_rest
> +
> +            sys.stderr.write(out)
> 

-- 
—js