I write it as a (memo) for myself, but I hope some people will find it useful. For the time being, I will start scratching at the level, so I welcome you.
Here are some things to keep in mind when using python's argparse to send information to a class.
Create the following as x.py
#!/usr/bin/env python
import sys
import argparse
import unittest
class testtst(unittest.TestCase):
def setUp(self):
pass
PARSER = argparse.ArgumentParser()
PARSER.add_argument("--browser")
# MY_Make an ARGS and send it.
MY_ARGS = PARSER.parse_args()
if __name__ == "__main__":
"""
#Without this part, an error will occur.
if sys.argv:
del sys.argv[1:]
"""
unittest.main()
If you execute the following, an error will occur.
python x.py --browser Chrome
usage: x.py [-h] [--broswer BROSWER]
x.py: error: unrecognized arguments: --browser Chrome
Please comment out the part that will result in an error if this part is missing.
Recommended Posts