예제 #1
0
    def configure(self):
        if self.args is None:
            self.args = sys.argv[:]
        # Check to see if we are being run as a subprocess. If we are,
        # then use the resume-layer and defaults passed in.
        if len(self.args) > 1 and self.args[1] == '--resume-layer':
            self.args.pop(1)
            resume_layer = self.args.pop(1)
            resume_number = int(self.args.pop(1))
            self.defaults = []
            while len(self.args) > 1 and self.args[1] == '--default':
                self.args.pop(1)
                self.defaults.append(self.args.pop(1))

            sys.stdin = FakeInputContinueGenerator()
        else:
            resume_layer = resume_number = None

        options = get_options(self.args, self.defaults)

        options.testrunner_defaults = self.defaults
        options.resume_layer = resume_layer
        options.resume_number = resume_number

        self.options = options

        self.features.append(zope.testing.testrunner.selftest.SelfTest(self))
        self.features.append(zope.testing.testrunner.logsupport.Logging(self))
        self.features.append(zope.testing.testrunner.coverage.Coverage(self))
        self.features.append(zope.testing.testrunner._doctest.DocTest(self))
        self.features.append(zope.testing.testrunner.profiling.Profiling(self))
        if is_jython:
            # Jython GC support is not yet implemented
            pass
        else:
            self.features.append(
                zope.testing.testrunner.garbagecollection.Threshold(self))
            self.features.append(
                zope.testing.testrunner.garbagecollection.Debug(self))

        self.features.append(zope.testing.testrunner.find.Find(self))
        self.features.append(zope.testing.testrunner.shuffle.Shuffle(self))
        self.features.append(zope.testing.testrunner.process.SubProcess(self))
        self.features.append(zope.testing.testrunner.filter.Filter(self))
        self.features.append(zope.testing.testrunner.listing.Listing(self))
        self.features.append(
            zope.testing.testrunner.statistics.Statistics(self))
        self.features.append(zope.testing.testrunner.tb_format.Traceback(self))

        # Remove all features that aren't activated
        self.features = [f for f in self.features if f.active]
예제 #2
0
def preload_plone():
    print "Preloading Plone ..."
    plone_layer = setup_plone()
    # pre-setup Plone layer
    setup_layers={}
    from zope.testing.testrunner import runner
    from zope.testing.testrunner.options import get_options
    options = get_options([], [])
    runner.setup_layer(options, plone_layer, setup_layers)
    # delete the plone layer registration so that the testrunner
    # will re-run Plone layer setUp after deferred setups have
    # been registered by the associated tests.
    del setup_layers[plone_layer] 
    return setup_layers
예제 #3
0
def preload_plone(options=None):
    plone_layer = setup_plone()
    # pre-setup Plone layer
    setup_layers={}

    if options is None:
        options = get_options([], [])

    import zope.testing.testrunner.runner
    zope.testing.testrunner.runner.setup_layer(options, plone_layer, setup_layers)

    # delete the plone layer registration so that the testrunner
    # will re-run Plone layer setUp after deferred setups have
    # been registered by the associated tests.
    del setup_layers[plone_layer] 
    return setup_layers
예제 #4
0
    def test_preload_plone(self):
        from roadrunner import runner

        setup_plone = self.mocker.replace('roadrunner.runner.setup_plone')
        setup_plone()
        self.mocker.result(None)

        from zope.testing.testrunner.options import get_options
        options = get_options([], [])

        from mocker import ANY
        setup_layer = self.mocker.replace('zope.testing.testrunner.runner.setup_layer')
        setup_layer(ANY, ANY, ANY)
        self.mocker.call(fake_setup_layer)
        
        self.mocker.replay()
        layers = runner.preload_plone(options=options)
        self.assertEquals(layers, {})
예제 #5
0
def main():
    # The working directory change is just so that the test script
    # can be invoked from places other than the root of the source
    # tree. This is very useful for IDE integration, so an IDE can
    # e.g. run the test that you are currently editing.
    there = os.getcwd()
    os.chdir(config.root)

    fix_doctest_output()
    configure_environment()
    filter_warnings()
    install_fake_pgsql_connect()
    randomise_listdir()

    # The imports at the top of this file must avoid anything that reads
    # from Launchpad config. Now that we've set the correct config instance,
    # we can safely import the rest.
    from lp.services.testing.customresult import (
        filter_tests,
        patch_find_tests,
    )
    from lp.services.testing import profiled

    # Extract arguments so we can see them too. We need to strip
    # --resume-layer and --default stuff if found as get_options can't
    # handle it.
    if len(sys.argv) > 1 and sys.argv[1] == '--resume-layer':
        main_process = False
        args = list(sys.argv)
        args.pop(1)  # --resume-layer
        args.pop(1)  # The layer name
        args.pop(1)  # The resume number
        while len(args) > 1 and args[1] == '--default':
            args.pop(1)  # --default
            args.pop(1)  # The default value
        args.insert(0, sys.argv[0])
    else:
        main_process = True
        args = sys.argv

    # thunk across to parallel support if needed.
    if '--parallel' in sys.argv and '--list-tests' not in sys.argv:
        # thunk over to parallel testing.
        from lp.services.testing.parallel import main
        sys.exit(main(sys.argv))

    def load_list(option, opt_str, list_name, parser):
        patch_find_tests(filter_tests(list_name, '--shuffle' in sys.argv))

    options.parser.add_option('--load-list',
                              type=str,
                              action='callback',
                              callback=load_list)
    options.parser.add_option('--parallel',
                              action='store_true',
                              help='Run tests in parallel processes. '
                              'Poorly isolated tests will break.')

    # tests_pattern is a regexp, so the parsed value is hard to compare
    # with the default value in the loop below.
    options.parser.defaults['tests_pattern'] = defaults['tests_pattern']
    local_options = options.get_options(args=args)
    # Set our default options, if the options aren't specified.
    for name, value in defaults.items():
        parsed_option = getattr(local_options, name)
        if ((parsed_option == [])
                or (parsed_option == options.parser.defaults.get(name))):
            # The option probably wasn't specified on the command line,
            # let's replace it with our default value. It could be that
            # the real default (as specified in
            # zope.testing.testrunner.options) was specified, and we
            # shouldn't replace it with our default, but it's such and
            # edge case, so we don't have to care about it.
            options.parser.defaults[name] = value

    # Turn on Layer profiling if requested.
    if local_options.verbose >= 3 and main_process:
        profiled.setup_profiling()

    try:
        try:
            testrunner.run([])
        except SystemExit:
            # Print Layer profiling report if requested.
            if main_process and local_options.verbose >= 3:
                profiled.report_profile_stats()
            raise
    finally:
        os.chdir(there)