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():
assert "b" != "c"
def test_xxx_stdalone():
assert "xxx" == "xxx"
class TestClass(object):
def setUp(self):
pass
def tearDown(self):
pass
def test_equality(self):
assert "a" == "a"
def test_xxx(self):
assert "xxx" == "xxx"
if __name__ == "__main__":
nose.main(argv=sys.argv[:] + ["-v", "-m", ".*equality.*", __file__])
This test script upon execution yields -
zzztest.test_equality_stdalone ... ok
zzztest.test_inequality_stdalone ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.003s
OK
While this -
nose.main(argv=sys.argv[:] + ["-v", "-m", ".*Class.*", __file__])
yields -
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
And this -
nose.main(argv=sys.argv[:] + ["-v", "-m", "", __file__])
yields -
zzztest.TestClass.test_equality ... ok
zzztest.TestClass.test_xxx ... ok
zzztest.test_equality_stdalone ... ok
zzztest.test_inequality_stdalone ... ok
zzztest.test_xxx_stdalone ... ok
----------------------------------------------------------------------
Ran 5 tests in 0.004s
OK
Could someone please help me in figuring out how to select only a few methods from the TestClass for testing?
P.S. -
As per documentation (below) nose.main(argv=sys.argv[:] + ["-v", "-m", ".*Class.*", __file__])
should have picked up at least a couple of tests.
-m REGEX, --match=REGEX, --testmatch=REGEX
Files, directories, function names, and class names
that match this regular expression are considered
tests. Default: (?:^|[\b_\.\-])[Tt]est
[NOSE_TESTMATCH]
P.P.S. - Not a duplicate of nose framework command line regex pattern matching doesnt work(-e,-m ,-i). If you read the question and saw the 3 different inputs that I pass to nose.main() then you would see that the problem is not that the "-m" filter is not working at all, but that it works only for standalone test cases while always ignoring methods from TestClass.