I need to stub
In : from StringIO import StringIO
In : with StringIO("foo") as f: f.read()
--> AttributeError: StringIO instance has no attribute '__exit__'
The StringIO module predates the with statement. Since StringIO has been removed in Python 3 anyways, you can just use its replacement, io.BytesIO:
>>> import io
>>> with io.BytesIO(b"foo") as f: f.read()