如果你用python filename.py -d abc调用以下程序,你会得到unittest的帮助。如果你调用filename.py /d abc,则会得到以下错误信息:
AttributeError: 'module' object has no attribute '/d'
我想创建自己的CLI开关,以指定配置文件或其他CLI开关。我也尝试了--d。是否有一种方法使unittest接受其他的开关?
AttributeError: 'module' object has no attribute '/d'
我想创建自己的CLI开关,以指定配置文件或其他CLI开关。我也尝试了--d。是否有一种方法使unittest接受其他的开关?
import unittest
class SomeTests(unittest.TestCase):
def test_one(self):
theTest( 'keith' )
def test_two(self):
otherTest( 'keith')
if __name__ == '__main__':
unittest.main( argv=sys.argv, testRunner = unittest.TextTestRunner(verbosity=2))
for
循环解析参数,对于每个参数,您将执行某些操作(例如设置变量或运行一些代码)。请查看如何在Python中使用 getopt/OPTARG?。 - mtm