I want to test a python file with pytest which contains a if __name__ == '__main__':
it also has arguments parsed in it.
the code is something like this:
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Execute job.')
parser.add_argument('--env', required=True, choices=['qa', 'staging', 'prod'])
args = parser.parse_args()
# some logic
The limitation here is I cannot add a main()
method and wrap the logic in if __name__ == '__main__':
inside it and run it from there!
The code is a legacy code and cannot be changed!
I want to test this with pytest, I wonder how can I run this python file with some arguments inside my test?