1 year ago
#362004
hehe
How can I do unit test when the input string is set as FileType in argparse for python command line program?
The code (file_name.readline()
) will not run if I pass a string file_name in the test program (as expected). I need to test several different files for one method.
Is the only solution not to use FileType but str in argparse?
parser = argparse.ArgumentParser(description='XXX')
parser.add_argument('file_name', type=argparse.FileType('r'), help='Please choose a file.')
python
unit-testing
argparse
readline
0 Answers
Your Answer