1
""" Add unit and functional testing support to setuptools-driven eggs.
3
from setuptools.command.test import ScanningLoader
4
from setuptools.command.test import test as BaseCommand
8
""" Walk the suite returned by setuptools' testloader.
10
o Skip any tests which have a 'layer' defined.
12
from unittest import TestSuite
14
for test in suite._tests:
15
if isinstance(test, TestSuite):
16
result.addTest(skipLayers(test))
18
layer = getattr(test, 'layer', None)
23
class SkipLayers(ScanningLoader):
24
""" Load only unit tests (those which have no layer associated with them).
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.
31
o To run layer-dependent tests, use 'setup.py ftest' (see below for
32
adding the command to your setup.py).
34
o To use this loader your pacakge add the following your 'setup()'
39
setup_requires=['eggtestinfo' # captures testing metadata in EGG-INFO
41
tests_require=['zope.testing >= 3.6.1dev', #XXX fix version at release
44
test_loader='zope.testing.testrunner.eggsupport:SkipLayers',
48
def loadTestsFromModule(self, module):
49
return skipLayers(ScanningLoader.loadTestsFromModule(self, module))
52
print 'python setup.py ftest'
56
class ftest(BaseCommand):
57
""" Run unit and functional tests after an in-place build.
59
o Note that this command runs *all* tests (unit *and* functional).
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
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.
71
o To use this in your pacakge add the following to the 'entry_points'
76
setup_requires=['zope.testing >= 3.6.1dev', #XXX fix version at release
77
'eggtestinfo' # captures testing metadata in EGG-INFO
82
ftest = zope.testing.testrunner.eggsupport:SetuptoolsFunctionalTest
87
description = "Run all functional and unit tests after in-place build"
89
help_options = [('usage', '?', 'Show usage', print_usage)]
91
def initialize_options(self):
92
pass # suppress normal handling
94
def finalize_options(self):
95
pass # suppress normal handling
98
from zope.testing.testrunner import run
100
dist = self.distribution
101
where = dist.package_dir or '.'
102
args = ['IGNORE_ME', '--test-path', where]
104
if dist.install_requires:
105
dist.fetch_build_eggs(dist.install_requires)
107
if dist.tests_require:
108
dist.fetch_build_eggs(dist.tests_require)
113
self.with_project_on_sys_path(_run)