我有一个模块导入unittest并有一些TestCases.我想接受一些命令行选项(例如下面,数据文件的名称),但是当我尝试传递选项时,我收到消息"选项-i not recognized".是否可以让unittest +为应用程序提供选项(注意:我使用optparse来处理选项)?谢谢.
$ python test_app_data.py -i data_1.txt
option -i not recognized
Run Code Online (Sandbox Code Playgroud)
=====================
后续行动:这是建议解决方案的实施:
import cfg_master #has the optparse option-handling code
...
if __name__ == '__main__':
#add you app's options here...
options_tpl = ('-i', '--in_dir', '-o', '--out_dir')
del_lst = []
for i,option in enumerate(sys.argv):
if option in options_tpl:
del_lst.append(i)
del_lst.append(i+1)
del_lst.reverse()
for i in del_lst:
del sys.argv[i]
unittest.main()
Run Code Online (Sandbox Code Playgroud) 我有一个名为"example"的库,我将其安装到我的全局site-packages目录中.但是,我希望能够安装两个版本,一个用于生产,一个用于测试(我有一个Web应用程序和其他以这种方式版本化的东西).
有没有办法指定,比如"python setup.py stage",它不仅会将不同的蛋安装到site-packages中,还会将模块从"example"重命名为"example_stage"或类似的东西?
如果distutils无法做到这一点,还有其他工具吗?