问题描述
显然,回答我的问题是没有,但我可以通过一个 - 覆盖包= PACKAGE
选项鼻子目录中的每个.py文件的包名
因此,例如,如果该目录包含:
foo.py
bar.py
baz.py
...然后我会需要使用命令:
nosetests --with覆盖--coverage包= foo的--coverage包=酒吧--coverage包=巴兹
所以我的问题是,有人可以写一些shell脚本code(preferably sh或bash)的取当前目录下的所有文件名带有.py扩展,产生上述命令行(用在扩展的.py删除)?我的bash技能是相当有限的。 (我很想做它在Python)。
nosetests --with覆盖$(为*的.py F;做回声--cover包= $ {。F%*};完成)
关键是这里使用删除文件扩展名。
$ {F%。*}
Apparently the answer to my question "Can I restrict nose coverage output to directory (rather than package)?" is no, but I can pass a --coverage-package=PACKAGE
option to nose with the package name of each .py file in the directory.
So for example, if the directory contains:
foo.py
bar.py
baz.py
...then I would need to use the command:
nosetests --with-coverage --coverage-package=foo --coverage-package=bar --coverage-package=baz
So my question is, can someone write some shell script code (preferably sh or bash) to take all the filenames in the current directory with a .py extension and generate the above command-line (with the .py extensions removed)? My bash skills are quite limited. (I'm tempted to just do it in Python.)
nosetests --with-coverage $(for f in *.py; do echo --cover-package="${f%.*}"; done)
The trick is here is using parameter substitution to remove the file extension.
${f%.*}
这篇关于我怎样写一些(bash)的shell脚本到所有匹配文件名转换成目录下的命令行选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!