I have a test case where I'd like to be able to run a python file with arguments.
I have 2 files. app.py
def process_data(arg1,arg2,arg3): return {'msg':'ok'} if __name__ == "__main__": arg1 = sys.argv[1] arg2 = sys.argv[2] arg3 = sys.argv[3] process_data(arg1,arg2,arg3) test_cases.py
class TestCase(unittest.TestCase): def test_case1(self): expected_output = {'msg':'ok'} with os.popen("echo python app.py arg1 arg2 arg3") as o: output = o.read() output = output.strip() self.assertEqual(output, expected_output) if __name__ == "__main__": unittest.main() expected result is {'msg':'ok'} however the variable output returns nothing.
return {'msg':'ok'}toprint({'msg':'ok'}){'msg':'ok'}and compare that toexpected_output's dictionary:{'msg':'ok'}.