Re: [PATCH] kunit: tool: misc fixes (unused vars, imports, leaked files)

From: Daniel Latypov
Date: Tue Sep 28 2021 - 22:12:39 EST

On Tue, Sep 28, 2021 at 5:34 PM 'David Gow' via KUnit Development
<kunit-dev@xxxxxxxxxxxxxxxx> wrote:
> On Wed, Sep 29, 2021 at 6:11 AM Daniel Latypov <dlatypov@xxxxxxxxxx> wrote:
> >
> > Drop some variables in unit tests that were unused and/or add assertions
> > based on them.
> >
> > For ExitStack, it was imported, but the `es` variable wasn't used so it
> > didn't do anything, and we were leaking the file objects.
> > Refactor it to just use nested `with` statements to properly close them.
> >
> > And drop the direct use of .close() on file objects in the kunit tool
> > unit test, as these can be leaked if test assertions fail.
> To clarify for a python novice: this is referring to using "with" so
> that the file isn't leaked if the assertion fails, rather than
> suggesting that leaks are okay for failing tests, right?

Ah, I see how it can be misread now.

But on that note, it's probably fine to leak the files as CPython
should close the file object during GC.
And tests failing should make those file objects go out of scope immediately.

> > Signed-off-by: Daniel Latypov <dlatypov@xxxxxxxxxx>
> > ---
> These all seem sensible to me. Thanks for cleaning this up!
> Reviewed-by: David Gow <davidgow@xxxxxxxxxx>
> -- David
> --
> You received this message because you are subscribed to the Google Groups "KUnit Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kunit-dev+unsubscribe@xxxxxxxxxxxxxxxx.
> To view this discussion on the web visit