~landscape/zope3/newer-from-ztk

« back to all changes in this revision

Viewing changes to src/zope/testing/testrunner/eggsupport.py

  • Committer: Thomas Hervé
  • Date: 2009-09-21 16:46:07 UTC
  • Revision ID: thomas@canonical.com-20090921164607-sky3xhlt02ji80ka
Revert r8: regression with test failures

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
""" Add unit and functional testing support to setuptools-driven eggs.
2
 
"""
3
 
from setuptools.command.test import ScanningLoader
4
 
from setuptools.command.test import test as BaseCommand
5
 
 
6
 
 
7
 
def skipLayers(suite):
8
 
    """ Walk the suite returned by setuptools' testloader.
9
 
    
10
 
    o Skip any tests which have a 'layer' defined.
11
 
    """
12
 
    from unittest import TestSuite
13
 
    result = TestSuite()
14
 
    for test in suite._tests:
15
 
        if isinstance(test, TestSuite):
16
 
            result.addTest(skipLayers(test))
17
 
        else:
18
 
            layer = getattr(test, 'layer', None)
19
 
            if layer is None:
20
 
                result.addTest(test)
21
 
    return result
22
 
 
23
 
class SkipLayers(ScanningLoader):
24
 
    """ Load only unit tests (those which have no layer associated with them).
25
 
 
26
 
    o Running the tests using 'setup.py test' cannot, by default, drive the
27
 
      full testrunner, with its support for layers (in functional tests).
28
 
      This loader allows the command to work, by running only those tests
29
 
      which don't need the layer support.
30
 
 
31
 
    o To run layer-dependent tests, use 'setup.py ftest' (see below for
32
 
      adding the command to your setup.py).
33
 
 
34
 
    o To use this loader your pacakge add the following your 'setup()'
35
 
      call::
36
 
 
37
 
      setup(
38
 
      ...
39
 
      setup_requires=['eggtestinfo' # captures testing metadata in EGG-INFO
40
 
                     ],
41
 
      tests_require=['zope.testing >= 3.6.1dev', #XXX fix version at release
42
 
                    ],
43
 
      ...
44
 
      test_loader='zope.testing.testrunner.eggsupport:SkipLayers',
45
 
      ...
46
 
      )
47
 
    """
48
 
    def loadTestsFromModule(self, module):
49
 
        return skipLayers(ScanningLoader.loadTestsFromModule(self, module))
50
 
 
51
 
def print_usage():
52
 
    print 'python setup.py ftest'
53
 
    print
54
 
    print ftest.__doc__
55
 
 
56
 
class ftest(BaseCommand):
57
 
    """ Run unit and functional tests after an in-place build.
58
 
 
59
 
    o Note that this command runs *all* tests (unit *and* functional).
60
 
    
61
 
    o This command does not provide any of the configuration options which
62
 
      the usual testrunner provided by 'zope.testing' offers:  it is intended
63
 
      to allow easy verification that a package has been installed correctly
64
 
      via setuptools, but is not likely to be useful for developers working
65
 
      on the package.
66
 
 
67
 
    o Developers working on the package will likely prefer to work with
68
 
      the stock testrunner, e.g., by using buildout with a recipe which
69
 
      configures the testrunner as a standalone script.
70
 
 
71
 
    o To use this in your pacakge add the following to the 'entry_points'
72
 
      section::
73
 
 
74
 
      setup(
75
 
      ...
76
 
      setup_requires=['zope.testing >= 3.6.1dev', #XXX fix version at release
77
 
                      'eggtestinfo' # captures testing metadata in EGG-INFO
78
 
                     ],
79
 
      ...
80
 
      entry_points='''
81
 
      [setuptools.commands]
82
 
      ftest = zope.testing.testrunner.eggsupport:SetuptoolsFunctionalTest
83
 
      '''
84
 
      ...
85
 
      )
86
 
    """
87
 
    description = "Run all functional and unit tests after in-place build"
88
 
    user_options = []
89
 
    help_options = [('usage', '?', 'Show usage', print_usage)]
90
 
 
91
 
    def initialize_options(self):
92
 
        pass # suppress normal handling
93
 
 
94
 
    def finalize_options(self):
95
 
        pass # suppress normal handling
96
 
 
97
 
    def run(self):
98
 
        from zope.testing.testrunner import run
99
 
 
100
 
        dist = self.distribution
101
 
        where = dist.package_dir or '.'
102
 
        args = ['IGNORE_ME', '--test-path', where]
103
 
 
104
 
        if dist.install_requires:
105
 
            dist.fetch_build_eggs(dist.install_requires)
106
 
 
107
 
        if dist.tests_require:
108
 
            dist.fetch_build_eggs(dist.tests_require)
109
 
 
110
 
        def _run():
111
 
            run(args=args)
112
 
 
113
 
        self.with_project_on_sys_path(_run)
114