I do a lot of coding in python and got a lot of if
conditions without an else
statement so to say partial branches.
E.g.:
# if a certain kwarg was passed to a function call
if kwargs.get('a_option'):
# overwrite an entry in an already existing dict:
config['a_option'] = kwargs['a_option']
This always shows up in my test coverage as a partial hit unless I mark it with a pragma: no branch
.
So my question is, is it considered bad practice to use partial branches? And if it is, are there any popular ways how to avoid them? (not something like "just add else without any statements like in python else: pass
")
Note that this is refering to branching in general and not only python. I just used that as example but I'm interested in general how such things are handled in no matter what language.
else
blocks.coverage.py
is considering theelse
part of a branch as a lack of coverage (showing in the coverage percentage unless excluded with the pragma). But I guessed this implicates either bad practice in my coding or this is just related to the interpretation of my tests and the coverage. I mean, why should I test anelse: do nothing
. Maybe it's just me being confused about why the coverage is even warning about this and concluding, there could be a design flaw.