7

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?

4

4 回答 4

11

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.

于 2013-08-22T19:43:07.417 回答
3

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'
于 2016-03-22T17:17:23.523 回答
1

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'
于 2013-08-05T18:02:13.757 回答
0

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.

于 2019-05-10T07:29:17.417 回答