[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201202190824.1309398-1-dlatypov@google.com>
Date: Wed, 2 Dec 2020 11:08:21 -0800
From: Daniel Latypov <dlatypov@...gle.com>
To: davidgow@...gle.com
Cc: brendanhiggins@...gle.com, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org, skhan@...uxfoundation.org,
Daniel Latypov <dlatypov@...gle.com>
Subject: [PATCH v2 1/4] kunit: tool: fix unit test cleanup handling
* 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@...gle.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: 509a15421674b9e1a3e1916939d0d0efd3e578da
--
2.29.2.576.ga3fc446d84-goog
Powered by blists - more mailing lists