Imported Upstream version 1.1.2
[platform/upstream/python-nose.git] / functional_tests / test_load_tests_from_test_case.py
1 """
2 Tests that plugins can override loadTestsFromTestCase
3 """
4 import os
5 import unittest
6 from nose import loader
7 from nose.plugins import PluginTester
8 from nose.plugins.base import Plugin
9
10
11 support = os.path.join(os.path.dirname(__file__), 'support')
12
13
14 class 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
38 class 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
55 if __name__ == '__main__':
56     unittest.main()