I am writing a unit test for the following function which is in my_script.py:
def _parse_args():
parser = argparse.ArgumentParser(
description='Script to configure appliance.'
)
parser.add_argument('--config_file',
help='Path to a JSON configuration file')
print parser.parse_args()
return parser.parse_args()
I want to create a unit test to mimic the command line prompt:
myscript.py --config_file test.json
This is what I have so far:
def test_parse_arg_test_config(self):
test ={
"name": "test_name",
"category": "test_category"
}
# set the fake command line prompt to be:
# myscript.py --config_file test
# (where test is defined above)
self.assertEquals(my_script._parse_args().config_file, test)
It is obviously incomplete, but I was wondering if I am approaching this the correct way since _parse_args
doesn't take in any inputs I don't know a different way to mimic a config file being passed into the function.
Aucun commentaire:
Enregistrer un commentaire