Excluding directory, module in python nosetest

∥☆過路亽.° 提交于 2019-12-04 02:46:55

问题


We use nose to discover tests and run them. All the tests are written in TestCase compatible way so any test runner can run the. Problem is we have some directories which doesn't have any test. But test runner continue to discover test from there. If one of those directory has lot of files its stuck. So how can I exclude that directory?

Currently I am executing

nosetests --processes=10 --verbosity 2

But there is a directory called scripts which takes ages to discover tests from it. So I want to exclude it. I tried

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

But no luck.


回答1:


There is a nose-exclude plugin specifically for the task:

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

Among other features, it introduces a new command-line argument called exclude-dir:

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

Instead of passing a command-line argument, you can also set NOSE_EXCLUDE_DIRS environment variable, or set exclude-dir configuration key in .noserc or nose.cfg files.




回答2:


You can also use the --ignore-files argument to exclude specific files. Since this is using regular expressions, you can name your files inside your scripts/ folder to begin with a specific prefix that you can then use to match in a regex.

# 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

See: Nose documentation.




回答3:


Perhaps not what the OP asked for, but I found this tidbit from the nose docs useful to exclude a file from consideration:

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.



来源:https://stackoverflow.com/questions/24263365/excluding-directory-module-in-python-nosetest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!