linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] kunit: tool: fix unit test cleanup handling
@ 2020-11-30 23:32 Daniel Latypov
  2020-11-30 23:32 ` [PATCH 2/5] kunit: tool: fix unit test so it can run from non-root dir Daniel Latypov
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Daniel Latypov @ 2020-11-30 23:32 UTC (permalink / raw)
  To: davidgow
  Cc: brendanhiggins, linux-kernel, linux-kselftest, skhan, Daniel Latypov

* Stop leaking file objects.
* Use self.addCleanup() to ensure we call cleanup functions even if
setUp() fails.
* use mock.patch.stopall instead of more error-prone manual approach

Signed-off-by: Daniel Latypov <dlatypov@google.com>
---
 tools/testing/kunit/kunit_tool_test.py | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index 497ab51bc170..3fbe1acd531a 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -288,19 +288,17 @@ class StrContains(str):
 class KUnitMainTest(unittest.TestCase):
 	def setUp(self):
 		path = get_absolute_path('test_data/test_is_test_passed-all_passed.log')
-		file = open(path)
-		all_passed_log = file.readlines()
-		self.print_patch = mock.patch('builtins.print')
-		self.print_mock = self.print_patch.start()
+		with open(path) as file:
+			all_passed_log = file.readlines()
+
+		self.print_mock = mock.patch('builtins.print').start()
+		self.addCleanup(mock.patch.stopall)
+
 		self.linux_source_mock = mock.Mock()
 		self.linux_source_mock.build_reconfig = mock.Mock(return_value=True)
 		self.linux_source_mock.build_um_kernel = mock.Mock(return_value=True)
 		self.linux_source_mock.run_kernel = mock.Mock(return_value=all_passed_log)
 
-	def tearDown(self):
-		self.print_patch.stop()
-		pass
-
 	def test_config_passes_args_pass(self):
 		kunit.main(['config', '--build_dir=.kunit'], self.linux_source_mock)
 		assert self.linux_source_mock.build_reconfig.call_count == 1

base-commit: b65054597872ce3aefbc6a666385eabdf9e288da
-- 
2.29.2.454.gaff20da3a2-goog


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

end of thread, other threads:[~2020-12-02 19:12 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30 23:32 [PATCH 1/5] kunit: tool: fix unit test cleanup handling Daniel Latypov
2020-11-30 23:32 ` [PATCH 2/5] kunit: tool: fix unit test so it can run from non-root dir Daniel Latypov
2020-12-01  7:32   ` David Gow
2020-12-01 18:59     ` Daniel Latypov
2020-12-02  4:41       ` David Gow
2020-12-02 19:11         ` Daniel Latypov
2020-11-30 23:32 ` [PATCH 3/5] kunit: tool: stop using bare asserts in unit test Daniel Latypov
2020-12-01  7:33   ` David Gow
2020-11-30 23:32 ` [PATCH 4/5] kunit: tool: use `with open()` " Daniel Latypov
2020-12-01  7:33   ` David Gow
2020-12-01 18:41     ` Daniel Latypov
2020-11-30 23:32 ` [PATCH 5/5] minor: kunit: tool: s/get_absolute_path/test_data_path " Daniel Latypov
2020-12-01  7:33   ` David Gow
2020-12-01  7:32 ` [PATCH 1/5] kunit: tool: fix unit test cleanup handling David Gow

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