[python-committers] Codecov and PR

Ethan Furman ethan at stoneleaf.us
Wed Apr 26 11:21:34 EDT 2017


On 04/25/2017 10:15 PM, INADA Naoki wrote:

> This is one examples I merged "untested line of code".
> https://github.com/python/cpython/pull/162/files#diff-0ad86c44e7866421ecaa5ad2c0edb0e2R552
>
> +            file_object = builtins.open(f, 'wb')
> +            try:
> +                self.initfp(file_object)
> +            except:
> +                file_object.close()
> +                raise
>
> `self.initfp()` is very unlikely raise exceptions.  But MemoryError,
> KeyboardInterrupt or
> other rare exceptions may be happen.
> Test didn't cover this except clause.  But I merged it because:
>
> * this code is simple enough.
> * I can write test for it with mocking `self.initfp()` to raise
> exception.  But such test code
>    have significant maintenance cost.  I don't think this except clause
> is important enough
>    to maintain such code.

I'm curious as to the maintenance cost -- surely it's write once, forget until you have to change that method again? 
How often are we changing that method?

> If I remove the except clause, all lines are tested, but there is
> (very unlikely)
> leaking unclosed file.  Which are "broken"?

Definitely the (unlikely) leaking of a file, possibly the untested closing of an otherwise leaked file.

> Coverage is very nice information to find code which should be tested,
> but not tested.
> But I don't think "all code should be tested".

All code should be tested.  Doesn't mean we can, but that should be the goal.

> It may make hard to improve Python.

Adding missing tests _is_ improving Python.

--
~Ethan~


More information about the python-committers mailing list