Shi*_*dim 17 python testing unit-testing nose
我们使用nose来发现测试并运行它们.所有测试都以TestCase兼容的方式编写,因此任何测试运行器都可以运行.问题是我们有一些没有任何测试的目录.但是测试运行者继续从那里发现测试.如果其中一个目录中有很多文件被卡住了.那我怎么能排除那个目录呢?
目前我正在执行
nosetests --processes=10 --verbosity 2
Run Code Online (Sandbox Code Playgroud)
但是有一个目录被称为scripts需要很长时间才能从中发现测试.所以我想排除它.我试过了
nosetests --processes=10 --verbosity 2 --exclude='^scripts$'
Run Code Online (Sandbox Code Playgroud)
但没有运气.
ale*_*cxe 18
有一个nose-exclude专门用于该任务的插件:
nose-exclude是一个Nose插件,允许您轻松指定要从测试中排除的目录.
在其他功能中,它引入了一个名为的新命令行参数exclude-dir:
nosetests --processes=10 --verbosity 2 --exclude-dir=/path/to/scripts
Run Code Online (Sandbox Code Playgroud)
而是传递一个命令行参数,你也可以设置NOSE_EXCLUDE_DIRS环境变量,或设置exclude-dir在配置项.noserc或nose.cfg文件.
gab*_*ous 11
您还可以使用该--ignore-files参数来排除特定文件.由于这是使用正则表达式,因此您可以将文件scripts/夹中的文件命名为以特定前缀开头,然后可以使用该前缀在正则表达式中进行匹配.
# Exclude just one test file
nosetests your_package --ignore-files="tests_to_exclude\.py" -v
# Exclude all python scripts beginning with `testskip_`
nosetests your_package --ignore-files="testskip_.+\.py" -v
Run Code Online (Sandbox Code Playgroud)
请参阅:鼻子文档.