nose framework command line regex pattern matching doesnt work(-e,-m ,-i)

烂漫一生 提交于 2019-12-06 00:34:44

问题


The python nosetest framework has some command line options to include, exclude and match regex for tests which can be included/excluded and matched respectively.

However they don't seem to be working correctly.

[kiran@my_redhat test]$ nosetests -w cases/ -s -v  -m='_size'
----------------------------------------------------------------------
Ran 0 tests in 0.001s
OK
[kiran@my_redhat test]$ grep '_size' cases/test_case_4.py
    def test_fn_size_sha(self):

is there some thing wrong with regex matching semantics of nose framework?


回答1:


Nosetests' -m argument is used to match directories, filenames, classes, and functions. (See the nose docs explanation of this parameter) In your case, the filename of your test file (test_case_4.py) does not match the -m match expression (_size), so is never opened.

You may notice that if you force nose to open your test file, it will run only the specified test:

nosetests -sv -m='_size' cases/test_case_4.py

In general, when I want to match specific tests or subsets of tests I use the --attrib plugin, which is available in the default nose install. You may also want to try excluding tests that match some pattern.




回答2:


Try removing '=' when specifying the regexp:

$ nosetests -w cases/ -s -v -m '_size'

or keep '=' and spell out --match:

$ nosetests -w cases/ -s -v --match='_size'



回答3:


Nose is likely using Python's re.match, or something equivalent, which requires a match at the beginning of the string. _size doesn't match because the function name test_fn_size_sha doesn't start with the regex _size.

Try using a regex that matches from the beginning:

nosetests -w cases/ -s -v -m='\w+_size'



回答4:


This works for me .

nosetests --collect-only test_mytest\test_category --exclude=test_.*Pin

Here I have excluded all test that has a word "Pin" in the test case name.

Note: All test case names start with test_ in my case.



来源:https://stackoverflow.com/questions/18064372/nose-framework-command-line-regex-pattern-matching-doesnt-work-e-m-i

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