Salim Fadhley Salim Fadhley - 1 year ago 75
Python Question

Is it possible to make Nose only run tests which are sub-classes of TestCase or TestSuite (like unittest.main())

My test framework is currently based on a test-runner utility which itself is derived from the Eclipse pydev python test-runner. I'm switching to use Nose, which has many of the features of my custom test-runner but seems to be better quality code.

My test suite includes a number of abstract test-classes which previously never ran. The standard python testrunner (and my custom one) only ran instances of unittest.TestCase and unittest.TestSuite.

I've noticed that since I switched to Nose it's running just about anything which starts withthe name "test" which is annoying... because the naming convention we used for the test-mixins also looks like a test class to Nose. Previously these never ran as tests because they were not instances of TestCase or TestSuite.

Obviously I could re-name the methods to exclude the word "test" from their names... that would take a while because the test framework is very big and has a lot of inheritance. On the other hand it would be neat if there was a way to make Nose only see TestCases and TestSuites as being runnable... and nothing else.

Can this be done?

Answer Source

You could try to play with -m option for nosetests. From documentation:

A test class is a class defined in a test module that matches testMatch or is a subclass of unittest.TestCase

-m sets that testMatch, this way you can disable testing anything starting with test.

Another thing is that you can add __test__ = False to your test case class declaration, to mark it “not a test”.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download