I am trying to listen to the print function from __main__.py. I use the patch function from unittest.mock.
def main_tester(command):
fake_command()
capturedoutput = io.StringIO()
sys.stdout = capturedoutput
with patch('sys.argv', command.split(" ")):
from SIESTAstepper import __main__ as rtmain
sys.stdout = sys.__stdout__
return capturedoutput.getvalue()
The problem is, it returns an empty string "" instead of the captured output.
The code is from here if you are willing to see the full project.