you should give except the exception condition like:
Then you can test by throwing a known illegal value to the code
except ValueError: ... # or except (ValueError, BufferError):Otherwise exceptions caused by something outside of your code block will not get caught
Then you can test by throwing a known illegal value to the code