Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 348
kbang Avatar asked Aug 05 '13 17:08

kbang


3 Answers

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.

like image 123
dbn Avatar answered Nov 13 '22 21:11

dbn


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'
like image 24
egor Avatar answered Nov 13 '22 23:11

egor


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'
like image 1
voithos Avatar answered Nov 13 '22 22:11

voithos