不包括python notes中的目录、模块

2024-04-20 12:39:16 发布

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

我们用鼻子发现测试并运行它们。所有测试都是以TestCase兼容的方式编写的,因此任何测试运行程序都可以运行。问题是我们有一些目录没有任何测试。但是测试运行人员继续从那里发现测试。如果其中一个目录有很多文件,它就会卡住。那我怎么才能排除那个目录呢?

目前我正在执行

nosetests --processes=10 --verbosity 2

但是有一个名为scripts的目录需要很长时间才能从中发现测试。所以我想排除它。我试过了

nosetests --processes=10 --verbosity 2 --exclude='^scripts$'

但没有运气。


Tags: 文件程序目录人员方式scriptsnoseteststestcase
3条回答

也许不是OP所要求的,但是我发现nose文档中的这个tidbit有助于从考虑中排除一个文件:

If an object defines a __test__ attribute that does not evaluate to True, that object will not be collected, nor will any objects it contains.

还可以使用--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

见:Nose documentation

有一个专门用于任务的^{}插件:

nose-exclude is a Nose plugin that allows you to easily specify directories to be excluded from testing.

在其他特性中,它引入了一个名为exclude-dir的新命令行参数:

nosetests --processes=10 --verbosity 2 --exclude-dir=/path/to/scripts

您还可以设置NOSE_EXCLUDE_DIRS环境变量,或者在^{} or ^{} files中设置exclude-dir配置键,而不是传递命令行参数。

相关问题 更多 >