Matching the nose command line regular expression pattern does not work (-e, -m, -i)

There are several command line options in the python nosetest structure to include, exclude, and match regular expression for tests that can be included / excluded and matched accordingly.

However, they do not seem to work 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 something wrong with the correct coincidence of the semantics of the nose frame?

+6
source share
4 answers

The Nosetests -m argument is used to match directories, file names , classes, and functions. ( See the explanation of this document . In your case, the test file name (test_case_4.py) does not match -m (_size), so it never opens.

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

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

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

+10
source

Try removing the '=' when specifying regexp:

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

or save '=' and --match spell:

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

The nose most likely uses Python re.match or something equivalent, which requires a match at the beginning of the line. _size does not match because the function name test_fn_size_sha does not start with regex _size .

Try using a regex that matches the beginning:

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

This works for me.

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

Here I excluded all tests that have the word "Pin" in their name.

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

0
source

Source: https://habr.com/ru/post/951054/


All Articles