Commit ff3caf5a authored by Max Reitz's avatar Max Reitz Committed by Kevin Wolf
Browse files

iotests.py: Add skip_for_formats() decorator



Sometimes, we want to skip some test methods for certain formats.  This
decorator allows that.

Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
Message-Id: <20200617104822.27525-2-mreitz@redhat.com>
Tested-by: default avatarThomas Huth <thuth@redhat.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
parent 6510ba1c
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -683,11 +683,10 @@ class TestBlockJobsAfterCycle(ChangeBaseClass):
        except OSError:
            pass

    def test_snapshot_and_commit(self):
    # We need backing file support
        if iotests.imgfmt != 'qcow2' and iotests.imgfmt != 'qed':
            return

    @iotests.skip_for_formats(('vpc', 'parallels', 'qcow', 'vdi', 'vmdk', 'raw',
                               'vhdx'))
    def test_snapshot_and_commit(self):
        result = self.vm.qmp('blockdev-snapshot-sync', device='drive0',
                                                       snapshot_file=new_img,
                                                       format=iotests.imgfmt)
+16 −0
Original line number Diff line number Diff line
@@ -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'''