* [PATCH] kunit: tool: suppress confusing error output in test
@ 2026-01-12 4:13 Jinseok Kim
2026-01-16 9:30 ` David Gow
0 siblings, 1 reply; 2+ messages in thread
From: Jinseok Kim @ 2026-01-12 4:13 UTC (permalink / raw)
To: brendan.higgins, davidgow
Cc: raemoar63, linux-kselftest, kunit-dev, linux-kernel, Jinseok Kim
When running kunit_tool_test.py, the test_run_raw_output_invalid test
prints invalid usage text and error messages to stderr. This happens because the
test triggers kunit.main() with an invalid argument, causing argparse to
print the usage and exit.
This output is confusing to the user because it looks like a test failure
or usage error, even though the test passed successfully. Furthermore,
argparse displays 'usage: kunit_tool_test.py run ...', which is misleading
since the test script itself does not accept the 'run' command.
This patch mocks sys.stderr in the test to suppress this expected error
output, making the test execution output cleaner.
Signed-off-by: Jinseok Kim <always.starving0@gmail.com>
---
tools/testing/kunit/kunit_tool_test.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index bbba921e0eac..7a8ba8e4f1d4 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -8,6 +8,7 @@
import unittest
from unittest import mock
+import io
import tempfile, shutil # Handling test_tmpdir
@@ -688,8 +689,9 @@ class KUnitMainTest(unittest.TestCase):
def test_run_raw_output_invalid(self):
self.linux_source_mock.run_kernel = mock.Mock(return_value=[])
- with self.assertRaises(SystemExit) as e:
- kunit.main(['run', '--raw_output=invalid'])
+ with mock.patch('sys.stderr', new=io.StringIO()):
+ with self.assertRaises(SystemExit) as e:
+ kunit.main(['run', '--raw_output=invalid'])
self.assertNotEqual(e.exception.code, 0)
def test_run_raw_output_does_not_take_positional_args(self):
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] kunit: tool: suppress confusing error output in test
2026-01-12 4:13 [PATCH] kunit: tool: suppress confusing error output in test Jinseok Kim
@ 2026-01-16 9:30 ` David Gow
0 siblings, 0 replies; 2+ messages in thread
From: David Gow @ 2026-01-16 9:30 UTC (permalink / raw)
To: Jinseok Kim
Cc: brendan.higgins, raemoar63, linux-kselftest, kunit-dev, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2363 bytes --]
On Mon, 12 Jan 2026 at 12:14, Jinseok Kim <always.starving0@gmail.com> wrote:
>
> When running kunit_tool_test.py, the test_run_raw_output_invalid test
> prints invalid usage text and error messages to stderr. This happens because the
> test triggers kunit.main() with an invalid argument, causing argparse to
> print the usage and exit.
>
> This output is confusing to the user because it looks like a test failure
> or usage error, even though the test passed successfully. Furthermore,
> argparse displays 'usage: kunit_tool_test.py run ...', which is misleading
> since the test script itself does not accept the 'run' command.
>
> This patch mocks sys.stderr in the test to suppress this expected error
> output, making the test execution output cleaner.
>
> Signed-off-by: Jinseok Kim <always.starving0@gmail.com>
> ---
This has been slightly annoying for a long time, so thanks for fixing it.
One minor nitpick in the commit description, otherwise this is good:
WARNING: Prefer a maximum 75 chars per line (possible unwrapped commit
description?)
#11:
prints invalid usage text and error messages to stderr. This happens because the
Reviewed-by: David Gow <davidgow@google.com>
Cheers,
-- David
> tools/testing/kunit/kunit_tool_test.py | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
> index bbba921e0eac..7a8ba8e4f1d4 100755
> --- a/tools/testing/kunit/kunit_tool_test.py
> +++ b/tools/testing/kunit/kunit_tool_test.py
> @@ -8,6 +8,7 @@
>
> import unittest
> from unittest import mock
> +import io
>
> import tempfile, shutil # Handling test_tmpdir
>
> @@ -688,8 +689,9 @@ class KUnitMainTest(unittest.TestCase):
>
> def test_run_raw_output_invalid(self):
> self.linux_source_mock.run_kernel = mock.Mock(return_value=[])
> - with self.assertRaises(SystemExit) as e:
> - kunit.main(['run', '--raw_output=invalid'])
> + with mock.patch('sys.stderr', new=io.StringIO()):
> + with self.assertRaises(SystemExit) as e:
> + kunit.main(['run', '--raw_output=invalid'])
> self.assertNotEqual(e.exception.code, 0)
>
> def test_run_raw_output_does_not_take_positional_args(self):
> --
> 2.43.0
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5281 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-16 9:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-12 4:13 [PATCH] kunit: tool: suppress confusing error output in test Jinseok Kim
2026-01-16 9:30 ` David Gow
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®