Re: [PATCH] semanage/test-semanage.py: Return non-zero value when some of unittest tests fail

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 11, 2020 at 1:23 PM Petr Lautrbach <plautrba@xxxxxxxxxx> wrote:
>
> Previously python/semanage/test-semanage.py returned 0 even when there was a
> fail in some test and `make test` didn't indicate any problem.
>
> Fixes:
>     $ make test
>     ...
>     Ran 10 tests in 110.854s
>     FAILED (failures=4)
>     $ echo $?
>     0
>
> Signed-off-by: Petr Lautrbach <plautrba@xxxxxxxxxx>

Acked-by: Nicolas Iooss <nicolas.iooss@xxxxxxx>

Nice catch! Thanks
Nicolas

> ---
>  python/semanage/test-semanage.py | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/python/semanage/test-semanage.py b/python/semanage/test-semanage.py
> index c8f6ec231fc2..d99e3fdaa211 100644
> --- a/python/semanage/test-semanage.py
> +++ b/python/semanage/test-semanage.py
> @@ -233,7 +233,7 @@ def semanage_custom_suite(test_list):
>
>
>  def semanage_run_test(suite):
> -    unittest.TextTestRunner(verbosity=2).run(suite)
> +    return unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful()
>
>
>  class CheckTest(argparse.Action):
> @@ -255,9 +255,9 @@ def semanage_args(args):
>          for i in semanage_test_list:
>              print(i)
>      if args.all:
> -        semanage_run_test(semanage_suite())
> +        return semanage_run_test(semanage_suite())
>      if args.test:
> -        semanage_run_test(semanage_custom_suite(args.test))
> +        return semanage_run_test(semanage_custom_suite(args.test))
>
>
>  def gen_semanage_test_args(parser):
> @@ -281,8 +281,10 @@ if __name__ == "__main__":
>          gen_semanage_test_args(parser)
>          try:
>              args = parser.parse_args()
> -            args.func(args)
> -            sys.exit(0)
> +            if args.func(args):
> +                sys.exit(0)
> +            else:
> +                sys.exit(1)
>          except ValueError as e:
>              sys.stderr.write("%s: %s\n" % (e.__class__.__name__, str(e)))
>              sys.exit(1)
> --
> 2.26.2
>




[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux