diff mbox series

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

Message ID 20200511112308.23523-1-plautrba@redhat.com (mailing list archive)
State Accepted
Headers show
Series semanage/test-semanage.py: Return non-zero value when some of unittest tests fail | expand

Commit Message

Petr Lautrbach May 11, 2020, 11:23 a.m. UTC
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@redhat.com>
---
 python/semanage/test-semanage.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Nicolas Iooss May 12, 2020, 7:40 p.m. UTC | #1
On Mon, May 11, 2020 at 1:23 PM Petr Lautrbach <plautrba@redhat.com> 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@redhat.com>

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

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
>
Petr Lautrbach May 13, 2020, 3:10 p.m. UTC | #2
On Mon, May 11, 2020 at 01:23:08PM +0200, Petr Lautrbach 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@redhat.com>
> Acked-by: Nicolas Iooss <nicolas.iooss@m4x.org>

Applied.

> ---
>  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)
diff mbox series

Patch

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)