I'm looking to unit test a class method that makes a function call to popen and performs some operations on it.
from os import popen
class myclass(object):
''' Generic class. '''
def do_something(self):
ret = popen("cat some_file")
# do some work with the returned value here
return modified_ret
I need to control what is returned from that popen call in order to test the method. What's the best way of going about that?
edit: I also have multiple methods that use popen in this single class; so if I could override it on the instance rather than the whole class that would be great.