]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: net: fix wrong boolean evaluation in __exit__
authorGal Pressman <gal@nvidia.com>
Sun, 25 Jan 2026 10:55:24 +0000 (12:55 +0200)
committerJakub Kicinski <kuba@kernel.org>
Tue, 27 Jan 2026 03:32:20 +0000 (19:32 -0800)
The __exit__ method receives ex_type as the exception class when an
exception occurs. The previous code used implicit boolean evaluation:

    terminate = self.terminate or (self._exit_wait and ex_type)
                                                   ^^^^^^^^^^^

In Python, the and operator can be used with non-boolean values, but it
does not always return a boolean result.

This is probably not what we want, because 'self._exit_wait and ex_type'
could return the actual ex_type value (the exception class) rather than
a boolean True when an exception occurs.

Use explicit `ex_type is not None` check to properly evaluate whether
an exception occurred, returning a boolean result.

Reviewed-by: Nimrod Oren <noren@nvidia.com>
Signed-off-by: Gal Pressman <gal@nvidia.com>
Link: https://patch.msgid.link/20260125105524.773993-1-gal@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/lib/py/utils.py

index 37243103aee35cdd89c6c236448c2b2b2aca24a1..85884f3e827b69dfe7cc15a4fddc0f61f1331900 100644 (file)
@@ -160,7 +160,7 @@ class bkg(cmd):
 
     def __exit__(self, ex_type, ex_value, ex_tb):
         # Force termination on exception
-        terminate = self.terminate or (self._exit_wait and ex_type)
+        terminate = self.terminate or (self._exit_wait and ex_type is not None)
         return self.process(terminate=terminate, fail=self.check_fail)