mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jinseok Kim <always.starving0@gmail.com>
To: brendan.higgins@linux.dev, davidgow@google.com
Cc: raemoar63@gmail.com, linux-kselftest@vger.kernel.org,
	kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org,
	Jinseok Kim <always.starving0@gmail.com>
Subject: [PATCH] kunit: tool: suppress confusing error output in test
Date: Sun, 11 Jan 2026 20:13:22 -0800	[thread overview]
Message-ID: <20260112041322.2168-1-always.starving0@gmail.com> (raw)

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

             reply	other threads:[~2026-01-12  4:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-12  4:13 Jinseok Kim [this message]
2026-01-16  9:30 ` David Gow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260112041322.2168-1-always.starving0@gmail.com \
    --to=always.starving0@gmail.com \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=raemoar63@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®