是否有一种方法可以将我自己的CLI切换到Untist File中



如果使用python filename.py -d abc调用下面的程序,您将获得UnitSest帮助。如果您致电filename.py/d abc,则会得到:

attributeError:'模块'对象没有属性'/d'

我想创建自己的CLI开关。指定配置文件或一些这样的CLI开关。我也尝试了 - d。是否有一种可以接受的方法可以接受其他开关?

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))

使用 sysgetopt模块来解析命令行选项和参数,从而使您可以使用简短和长的选项(例如-x and-long-option(。

最新更新