3 from nose.plugins import PluginTester, Plugin
4 from nose.tools import eq_
5 from cStringIO import StringIO
7 class StubPlugin(Plugin):
8 def options(self, parser, env=os.environ):
9 super(StubPlugin, self).options(parser, env=env)
10 def configure(self, options, conf):
13 class SomePluginTestCase(PluginTester):
14 activate = None # set this to --with-yourplugin, etc
15 plugins = [] # list of plugin instances
18 class SomeTest(unittest.TestCase):
20 raise ValueError("Now do something, plugin!")
21 return unittest.TestSuite([SomeTest()])
23 class TestPluginTester(unittest.TestCase):
24 def _runPluginTest(self, test_case):
25 loader = unittest.TestLoader()
26 suite = loader.loadTestsFromTestCase(test_case)
27 res = unittest.TestResult()
31 def testPluginTesterExecsPlugin(self):
33 class MockExecPlugin(StubPlugin):
34 def configure(self, options, conf):
35 called.append('configure')
37 class MockExecTestCase(SomePluginTestCase, unittest.TestCase):
38 activate = '--with-mockexec'
39 plugins = [MockExecPlugin()]
41 def test_something_anything(self):
42 # here is where the test case would test
43 # that the plugin interacted with stub tests
46 res = self._runPluginTest(MockExecTestCase)
48 eq_(called[0], 'configure')
50 if __name__ == '__main__':