File: test_load_tests_from_test_case.py

package info (click to toggle)
nose 1.3.7-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,712 kB
  • sloc: python: 15,697; makefile: 92; xml: 42; sh: 2
file content (57 lines) | stat: -rw-r--r-- 1,477 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Tests that plugins can override loadTestsFromTestCase
"""
import os
import unittest
from nose import loader
from nose.plugins import PluginTester
from nose.plugins.base import Plugin


support = os.path.join(os.path.dirname(__file__), 'support')


class NoFixturePlug(Plugin):
    enabled = True

    def options(self, parser, env):
        print "options"        
        pass
    
    def configure(self, options, conf):
        print "configure"
        pass

    def loadTestsFromTestCase(self, testCaseClass):
        print "Called!"
        class Derived(testCaseClass):
            def setUp(self):
                pass
            def tearDown(self):
                pass
        Derived.__qualname__ = Derived.__name__
        # must use nose loader here because the default loader in 2.3
        # won't load tests from base classes
        l = loader.TestLoader()
        return l.loadTestsFromTestCase(Derived)


class TestLoadTestsFromTestCaseHook(PluginTester, unittest.TestCase):

    activate = '-v'
    args = []
    plugins = [NoFixturePlug()]
    suitepath = os.path.join(support, 'ltftc')

    def runTest(self):
        expect = [
            'test_value (%s.Derived) ... ERROR' % __name__,
            'test_value (tests.Tests) ... ok']
        print str(self.output)
        for line in self.output:
            if expect:
                self.assertEqual(line.strip(), expect.pop(0))
                

if __name__ == '__main__':
    unittest.main()