[Qemu-devel] [PATCH v4 3/7] iotests: Use case_skip() in skip_if_unsupported()

Max Reitz posted 7 patches 6 years, 4 months ago
Maintainers: Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>
[Qemu-devel] [PATCH v4 3/7] iotests: Use case_skip() in skip_if_unsupported()
Posted by Max Reitz 6 years, 4 months ago
skip_if_unsupported() should use the stronger variant case_skip(),
because this allows it to be used even with setUp() (in a meaningful
way).

In the process, make it explicit what we expect the first argument of
the func_wrapper to be (namely something derived of QMPTestCase).

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

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index e46f3b6aed..427c34697a 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -893,14 +893,14 @@ def skip_if_unsupported(required_formats=[], read_only=False):
     '''Skip Test Decorator
        Runs the test if all the required formats are whitelisted'''
     def skip_test_decorator(func):
-        def func_wrapper(*args, **kwargs):
+        def func_wrapper(test_case: QMPTestCase, *args, **kwargs):
             usf_list = list(set(required_formats) -
                             set(supported_formats(read_only)))
             if usf_list:
-                case_notrun('{}: formats {} are not whitelisted'.format(
-                    args[0], usf_list))
+                test_case.case_skip('{}: formats {} are not whitelisted'.format(
+                    test_case, usf_list))
             else:
-                return func(*args, **kwargs)
+                return func(test_case, *args, **kwargs)
         return func_wrapper
     return skip_test_decorator
 
-- 
2.21.0


Re: [Qemu-devel] [PATCH v4 3/7] iotests: Use case_skip() in skip_if_unsupported()
Posted by Andrey Shinkevich 6 years, 4 months ago

On 17/09/2019 12:20, Max Reitz wrote:
> skip_if_unsupported() should use the stronger variant case_skip(),
> because this allows it to be used even with setUp() (in a meaningful
> way).
> 
> In the process, make it explicit what we expect the first argument of
> the func_wrapper to be (namely something derived of QMPTestCase).
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>   tests/qemu-iotests/iotests.py | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index e46f3b6aed..427c34697a 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -893,14 +893,14 @@ def skip_if_unsupported(required_formats=[], read_only=False):
>       '''Skip Test Decorator
>          Runs the test if all the required formats are whitelisted'''
>       def skip_test_decorator(func):
> -        def func_wrapper(*args, **kwargs):
> +        def func_wrapper(test_case: QMPTestCase, *args, **kwargs):
>               usf_list = list(set(required_formats) -
>                               set(supported_formats(read_only)))
>               if usf_list:
> -                case_notrun('{}: formats {} are not whitelisted'.format(
> -                    args[0], usf_list))
> +                test_case.case_skip('{}: formats {} are not whitelisted'.format(
> +                    test_case, usf_list))
>               else:
> -                return func(*args, **kwargs)
> +                return func(test_case, *args, **kwargs)
>           return func_wrapper
>       return skip_test_decorator
>   
> 

Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
-- 
With the best regards,
Andrey Shinkevich
Re: [Qemu-devel] [PATCH v4 3/7] iotests: Use case_skip() in skip_if_unsupported()
Posted by John Snow 6 years, 4 months ago

On 9/17/19 5:20 AM, Max Reitz wrote:
> skip_if_unsupported() should use the stronger variant case_skip(),
> because this allows it to be used even with setUp() (in a meaningful
> way).
> 
> In the process, make it explicit what we expect the first argument of
> the func_wrapper to be (namely something derived of QMPTestCase).
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>   tests/qemu-iotests/iotests.py | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index e46f3b6aed..427c34697a 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -893,14 +893,14 @@ def skip_if_unsupported(required_formats=[], read_only=False):
>       '''Skip Test Decorator
>          Runs the test if all the required formats are whitelisted'''
>       def skip_test_decorator(func):
> -        def func_wrapper(*args, **kwargs):
> +        def func_wrapper(test_case: QMPTestCase, *args, **kwargs):

The dream lives!

>               usf_list = list(set(required_formats) -
>                               set(supported_formats(read_only)))
>               if usf_list:
> -                case_notrun('{}: formats {} are not whitelisted'.format(
> -                    args[0], usf_list))
> +                test_case.case_skip('{}: formats {} are not whitelisted'.format(
> +                    test_case, usf_list))
>               else:
> -                return func(*args, **kwargs)
> +                return func(test_case, *args, **kwargs)
>           return func_wrapper
>       return skip_test_decorator
>   
> 

Reviewed-by: John Snow <jsnow@redhat.com>