Skip to content Skip to sidebar Skip to footer

How To Select Some Test Methods In A Fixture Using Regex (i.e. -m) In Nosetests?

Below is a pared down illustrative representation of my problem : import sys import nose def test_equality_stdalone(): assert 'b' == 'b' def test_inequality_stdalone():

Solution 1:

It is important to understand how nose does matching for what it wants as test. It happens independently for class names, function names and directories. Have a look at selector.py to clear up the mystery, but the short story is: your regex query must match the class name (TestClass in your case) AND class methods (test_equality or test_xxx) simultaneously. So if you would like to run TestClass.test_xxx you use something like:

nosetests zzztest.py -v --match="(TestClass|test_xxx$)"
zzztest.TestClass.test_xxx ... ok

----------------------------------------------------------------------
Ran 1 test in 0.002s

OK

If the class is not matched as part of the regex, it's methods are not viewed as tests and will not be evaluated against regex at all, thus you are getting 0 tests.

The only differentiator here is the dollar sign that matches class test method, but fails to match standalone method. If you have standalone and class methods named the same, you will not be able to differentiate between the two using --match regex filter.


Post a Comment for "How To Select Some Test Methods In A Fixture Using Regex (i.e. -m) In Nosetests?"