3 from nose.selector import Selector
4 from nose.plugins import Plugin
9 class MySelector(Selector):
10 def wantDirectory(self, dirname):
11 parts = dirname.split(os.path.sep)
12 return 'specs' in parts
13 def wantFile(self, filepath):
15 # we want python modules under specs/
16 dirname,filename = os.path.split(filepath)
17 base, ext = os.path.splitext(filename)
18 return self.wantDirectory(dirname) and ext == '.py' and base[0:2] != '__'
19 def wantModule(self, module):
20 # wantDirectory and wantFile above will ensure that
21 # we never see an unwanted module
23 def wantFunction(self, function):
24 # never collect functions
26 def wantClass(self, cls):
27 # only collect TestCase subclasses
28 return issubclass(cls, unittest.TestCase)
30 class UseMySelector(Plugin):
32 def configure(self, options, conf):
34 def prepareTestLoader(self, loader):
35 loader.selector = MySelector(loader.config)
36 nose.main(plugins=[UseMySelector()])