Re: [PATCH 1/5] kunit: tool: fix unit test cleanup handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Dec 1, 2020 at 7:32 AM Daniel Latypov <dlatypov@xxxxxxxxxx> wrote:
>
> * 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@xxxxxxxxxx>
> ---

I won't pretend to be an expert on Python, but this seems good to me.
I tested it on my machine and it works fine.

So,
Reviewed-by: David Gow <davidgow@xxxxxxxxxx>

-- Davkd

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



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux