PageRenderTime 32ms CodeModel.GetById 26ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/functional_tests/test_load_tests_from_test_case.py

https://bitbucket.org/jpellerin/nose/
Python | 56 lines | 38 code | 13 blank | 5 comment | 4 complexity | 3ea767e545f2862079b356d0ad5bfb7b MD5 | raw file
 1"""
 2Tests that plugins can override loadTestsFromTestCase
 3"""
 4import os
 5import unittest
 6from nose import loader
 7from nose.plugins import PluginTester
 8from nose.plugins.base import Plugin
 9
10
11support = os.path.join(os.path.dirname(__file__), 'support')
12
13
14class NoFixturePlug(Plugin):
15    enabled = True
16
17    def options(self, parser, env):
18        print "options"        
19        pass
20    
21    def configure(self, options, conf):
22        print "configure"
23        pass
24
25    def loadTestsFromTestCase(self, testCaseClass):
26        print "Called!"
27        class Derived(testCaseClass):
28            def setUp(self):
29                pass
30            def tearDown(self):
31                pass
32        # must use nose loader here because the default loader in 2.3
33        # won't load tests from base classes
34        l = loader.TestLoader()
35        return l.loadTestsFromTestCase(Derived)
36
37
38class TestLoadTestsFromTestCaseHook(PluginTester, unittest.TestCase):
39
40    activate = '-v'
41    args = []
42    plugins = [NoFixturePlug()]
43    suitepath = os.path.join(support, 'ltftc')
44
45    def runTest(self):
46        expect = [
47            'test_value (%s.Derived) ... ERROR' % __name__,
48            'test_value (tests.Tests) ... ok']
49        print str(self.output)
50        for line in self.output:
51            if expect:
52                self.assertEqual(line.strip(), expect.pop(0))
53                
54
55if __name__ == '__main__':
56    unittest.main()