Mocking iteration over file in Python
Posted on Sat 24 December 2011 in Coding • Tagged with file, mock, test, Python
Let’s say that I want to mock reading from a file using file’s iterator capability, i.e. (simplified version):
def readfile(f):
using open(f) as fd:
for line in fd:
yield line
I could mock the readfile
function, but then my mock would have to
replicate the …
Continue reading