python, unittest: is there a way to pass command line options to the app

后端 未结 5 982
余生分开走
余生分开走 2020-12-04 14:22

I have a module that imports unittest and has some TestCases. I would like to accept some command line options (for example below, the name of a data file), but when I try t

5条回答
  •  天涯浪人
    2020-12-04 15:04

    In your if __name__ == '__main__': section, which you're not showing us, you'll need to optparse and then del sys.argv[1:] before you pass control to unittest code, so that the latter code doesn't try to interpret your command line options again when you've already dealt with them. (It's a bit harder to have some options of your own and also pass some down to unittest, though it can be done if you do have such complex needs).

提交回复
热议问题