argparse和unittest python

2024-06-26 18:01:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用argparse处理命令行参数。代码运行良好。不过,一旦我补充unittest.main()总的来说,它不起作用。在

我得到了:

I am here 
option -i not recognized
Usage: testing.py [options] [test] [...]

Options:
  -h, --help       Show this message
  -v, --verbose    Verbose output
  -q, --quiet      Minimal output
  -f, --failfast   Stop on first failure
  -c, --catch      Catch control-C and display results
  -b, --buffer     Buffer stdout and stderr during test runs

Examples:
  testing.py                               - run default set of tests
  testing.py MyTestSuite                   - run suite 'MyTestSuite'
  testing.py MyTestCase.testSomething      - run MyTestCase.testSomething
  testing.py MyTestCase                    - run all 'test*' test methods
                                               in MyTestCase

我是这样做的:

^{pr2}$

Tags: andrun命令行pytestoutput参数main
1条回答
网友
1楼 · 发布于 2024-06-26 18:01:27

使用

runner = unittest.TextTestRunner()
itersuite = unittest.TestLoader().loadTestsFromTestCase(MyTestClass)
runner.run(itersuite)

而不是:

^{pr2}$

相关问题 更多 >