def _run():
     run(args=args)
Example #2
0
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Sample test script using zope.testing.testrunner

see zope.testing testrunner.txt
"""

import os, sys

here = os.path.abspath(os.path.dirname(sys.argv[0]))

# Remove this directory from path:
sys.path[:] = [p for p in sys.path if os.path.abspath(p) != here]

src = os.path.join(here, 'src')
sys.path.insert(0, src) # put at beginning to avoid one in site_packages

from zope.testing import testrunner

defaults = [
    '--path', src,
    '--package', 'zope.app.applicationcontrol',
    '--tests-pattern', '^f?tests$',
    ]

sys.exit(testrunner.run(defaults))
Example #3
0
        defaults += ['--package-path', products, 'Products']
else:
    defaults += ['--test-path', shome]

from zope.testing import testrunner

def load_config_file(option, opt, config_file, *ignored):
    config_file = os.path.abspath(config_file)
    print "Parsing %s" % config_file
    import Zope2
    Zope2.configure(config_file)

testrunner.setup.add_option(
    '--config-file', action="callback", type="string", dest='config_file',
    callback=load_config_file,
    help="""\
Initialize Zope with the given configuration file.
""")

def filter_warnings(option, opt, *ignored):
    import warnings
    warnings.simplefilter('ignore', Warning, append=True)

testrunner.other.add_option(
    '--nowarnings', action="callback", callback=filter_warnings,
    help="""\
Install a filter to suppress warnings emitted by code.
""")

sys.exit(testrunner.run(defaults))
Example #4
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)