selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] semanage/test-semanage.py: Return non-zero value when some of unittest tests fail
@ 2020-05-11 11:23 Petr Lautrbach
  2020-05-12 19:40 ` Nicolas Iooss
  2020-05-13 15:10 ` Petr Lautrbach
  0 siblings, 2 replies; 3+ messages in thread
From: Petr Lautrbach @ 2020-05-11 11:23 UTC (permalink / raw)
  To: selinux; +Cc: Petr Lautrbach

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(-)

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] semanage/test-semanage.py: Return non-zero value when some of unittest tests fail
  2020-05-11 11:23 [PATCH] semanage/test-semanage.py: Return non-zero value when some of unittest tests fail Petr Lautrbach
@ 2020-05-12 19:40 ` Nicolas Iooss
  2020-05-13 15:10 ` Petr Lautrbach
  1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Iooss @ 2020-05-12 19:40 UTC (permalink / raw)
  To: Petr Lautrbach; +Cc: SElinux list

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
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] semanage/test-semanage.py: Return non-zero value when some of unittest tests fail
  2020-05-11 11:23 [PATCH] semanage/test-semanage.py: Return non-zero value when some of unittest tests fail Petr Lautrbach
  2020-05-12 19:40 ` Nicolas Iooss
@ 2020-05-13 15:10 ` Petr Lautrbach
  1 sibling, 0 replies; 3+ messages in thread
From: Petr Lautrbach @ 2020-05-13 15:10 UTC (permalink / raw)
  To: selinux

[-- Attachment #1: Type: text/plain, Size: 2122 bytes --]

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)

-- 
()  ascii ribbon campaign - against html e-mail 
/\  www.asciiribbon.org   - against proprietary attachments

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-13 15:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11 11:23 [PATCH] semanage/test-semanage.py: Return non-zero value when some of unittest tests fail Petr Lautrbach
2020-05-12 19:40 ` Nicolas Iooss
2020-05-13 15:10 ` Petr Lautrbach

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).