Issue #470 duplicate
It looks to me as if all branches have been taken, but coverage disagrees. Problem disappears with context manager is removed or value is returned directly.
def soft_read(filename): try: with open(filename, 'r') as f: value = f.read() # line 4, partial coverage except: value = '' return value assert soft_read('missing file.txt') == '' assert len(soft_read(__file__))
Line 4 was executed, but never jumped to line 5