When reading an actual file with decode_file_iter, reading a stretch of bytes with an invalid size will raise an unexpected ValueError, rather than the expected InvalidBSON.
To reproduce:
import bson
with open('example.bson', 'wb') as outfile:
outfile.write(b'\0\0\0\0\0\0\0\0')
with open('example.bson', 'rb') as infile:
{{ list(bson.decode_file_iter(infile))}}
# This will raise 'ValueError: read length must be non-negative or -1'
The expected result is to raise an InvalidBSON, which is what the tests think will be raised. However, StringIO is more permissive than raw file input, in that it will allow reading arbitrary negative lengths.