From: Daniel Latypov <dlatypov@google.com>
To: davidgow@google.com
Cc: brendanhiggins@google.com, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org,
Daniel Latypov <dlatypov@google.com>
Subject: [PATCH 1/5] kunit: tool: fix unit test cleanup handling
Date: Mon, 30 Nov 2020 15:32:38 -0800 [thread overview]
Message-ID: <20201130233242.78413-1-dlatypov@google.com> (raw)
* 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
next reply other threads:[~2020-11-30 23:33 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-30 23:32 Daniel Latypov [this message]
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
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=20201130233242.78413-1-dlatypov@google.com \
--to=dlatypov@google.com \
--cc=brendanhiggins@google.com \
--cc=davidgow@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
/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