iotests.py: Add skip_for_formats() decorator
authorMax Reitz <mreitz@redhat.com>
Wed, 17 Jun 2020 10:48:18 +0000 (12:48 +0200)
committerKevin Wolf <kwolf@redhat.com>
Wed, 17 Jun 2020 14:21:21 +0000 (16:21 +0200)
Sometimes, we want to skip some test methods for certain formats.  This
decorator allows that.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200617104822.27525-2-mreitz@redhat.com>
Tested-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
tests/qemu-iotests/118
tests/qemu-iotests/iotests.py

index adc8a848b500b37f5c215e0d142224537b7c1b5e..2350929fd833f4ec2b4640a7891c7cc7a8bd1876 100755 (executable)
@@ -683,11 +683,10 @@ class TestBlockJobsAfterCycle(ChangeBaseClass):
         except OSError:
             pass
 
+    # We need backing file support
+    @iotests.skip_for_formats(('vpc', 'parallels', 'qcow', 'vdi', 'vmdk', 'raw',
+                               'vhdx'))
     def test_snapshot_and_commit(self):
-        # We need backing file support
-        if iotests.imgfmt != 'qcow2' and iotests.imgfmt != 'qed':
-            return
-
         result = self.vm.qmp('blockdev-snapshot-sync', device='drive0',
                                                        snapshot_file=new_img,
                                                        format=iotests.imgfmt)
index f20d90f96983d0b5f2b0b00548d6f285654b3dbb..5ea4c4df8b62595e01889345e0511b7d7c32a780 100644 (file)
@@ -1103,6 +1103,22 @@ def skip_if_unsupported(required_formats=(), read_only=False):
         return func_wrapper
     return skip_test_decorator
 
+def skip_for_formats(formats: Sequence[str] = ()) \
+    -> Callable[[Callable[[QMPTestCase, List[Any], Dict[str, Any]], None]],
+                Callable[[QMPTestCase, List[Any], Dict[str, Any]], None]]:
+    '''Skip Test Decorator
+       Skips the test for the given formats'''
+    def skip_test_decorator(func):
+        def func_wrapper(test_case: QMPTestCase, *args: List[Any],
+                         **kwargs: Dict[str, Any]) -> None:
+            if imgfmt in formats:
+                msg = f'{test_case}: Skipped for format {imgfmt}'
+                test_case.case_skip(msg)
+            else:
+                func(test_case, *args, **kwargs)
+        return func_wrapper
+    return skip_test_decorator
+
 def skip_if_user_is_root(func):
     '''Skip Test Decorator
        Runs the test only without root permissions'''