Beispiel #1
0
 def test_pretty_version(self):
     "pretty_version() has the content we expect"
     pv = pretty_version()
     self.assertTrue('Green' in pv)
     self.assertTrue('Python' in pv)
     if green.version.coverage:
         self.assertTrue('Coverage' in pv)
Beispiel #2
0
 def startTestRun(self):
     """
     Called once before any tests run
     """
     self.startTime = time.time()
     # Really verbose information
     if self.verbose > 2:
         self.stream.writeln(self.colors.bold(pretty_version() + "\n"))
Beispiel #3
0
 def startTestRun(self):
     """
     Called once before any tests run
     """
     self.startTime = time.time()
     # Really verbose information
     if self.verbose > 2:
         self.stream.writeln(self.colors.bold(pretty_version() + "\n"))
Beispiel #4
0
 def test_pretty_version(self):
     """
     pretty_version() has the content we expect
     """
     pv = pretty_version()
     self.assertTrue('Green' in pv)
     self.assertTrue('Python' in pv)
     self.assertTrue('Coverage' in pv)
 def test_pretty_version(self):
     """
     pretty_version() has the content we expect
     """
     pv = pretty_version()
     self.assertTrue("Green" in pv)
     self.assertTrue("Python" in pv)
     self.assertTrue("Coverage" in pv)
Beispiel #6
0
 def startTestRun(self):
     "Called once before any tests run"
     self.startTime = time.time()
     # Really verbose information
     if self.colors.html:
         self.stream.write(
                 '<div style="font-family: Monaco, \'Courier New\', monospace; color: rgb(170,170,170); background: rgb(0,0,0); padding: 14px;">')
     if self.verbose > 2:
         self.stream.writeln(self.colors.bold(pretty_version() + "\n"))
Beispiel #7
0
def mergeConfig(args, testing=False):  # pragma: no cover
    """
    I take in a namespace created by the ArgumentParser in cmdline.main() and
    merge in options from configuration files.  The config items only replace
    argument items that are set to default value.

    Returns: I return a new argparse.Namespace, adding members:
        shouldExit       = default False
        exitCode         = default 0
        include patterns = include-patterns setting converted to list.
        omit_patterns    = omit-patterns settings converted to list and
                           extended, taking clear-omit into account.
        cov              = coverage object default None
    """
    config = getConfig(getattr(args, 'config', default_args.config))
    new_args = copy.deepcopy(default_args)  # Default by default!

    for name, default_value in dict(default_args._get_kwargs()).items():
        # Config options overwrite default options
        config_getter = None
        if name in ['termcolor', 'notermcolor', 'allow_stdout', 'quiet_stdout',
                    'help', 'logging', 'version', 'disable_unidecode', 'failfast',
                    'run_coverage', 'options', 'completions', 'completion_file',
                    'clear_omit', 'no_skip_report', 'no_tracebacks',
                    'disable_windows', 'quiet_coverage', 'junit_report']:
            config_getter = config.getboolean
        elif name in ['processes', 'debug', 'verbose', 'minimum_coverage']:
            config_getter = config.getint
        elif name in ['file_pattern', 'finalizer', 'initializer',
                      'cov_config_file', 'include_patterns', 'omit_patterns',
                      'warnings', 'test_pattern']:
            config_getter = config.get
        elif name in ['targets', 'help', 'config']:
            pass  # Some options only make sense coming on the command-line.
        elif name in ['store_opt', 'parser']:
            pass  # These are convenience objects, not actual settings
        else:
            raise NotImplementedError(name)

        if config_getter:
            try:
                config_value = config_getter('green', name.replace('_', '-'))
                setattr(new_args, name, config_value)
            except (configparser.NoSectionError, configparser.NoOptionError):
                pass

        # Command-line values overwrite defaults and config values when
        # specified
        args_value = getattr(args, name, 'unspecified')
        if args_value != 'unspecified':
            setattr(new_args, name, args_value)

    new_args.shouldExit = False
    new_args.exitCode = 0
    new_args.cov = None

    # Help?
    if new_args.help:  # pragma: no cover
        new_args.parser.print_help()
        new_args.shouldExit = True
        return new_args

    # Did we just print the version?
    if new_args.version:
        from green.version import pretty_version
        sys.stdout.write(pretty_version()+'\n')
        new_args.shouldExit = True
        return new_args

    # Handle logging options
    if new_args.debug:
        logging.basicConfig(
                level=logging.DEBUG,
                format="%(asctime)s %(levelname)9s %(message)s",
                datefmt="%Y-%m-%d %H:%M:%S")
    elif not new_args.logging:
        logging.basicConfig(filename=os.devnull)

    # Disable termcolor?
    if new_args.notermcolor:
        new_args.termcolor = False

    # Coverage.  We must enable it here because we cannot cover module-level
    # code after it is imported, and this is the earliest place we can turn on
    # coverage.
    omit_patterns = [
        '*/argparse*',
        '*/colorama*',
        '*/django/*',
        '*/distutils*',        # Gets pulled in on Travis-CI CPython
        '*/extras*',           # pulled in by testtools
        '*/linecache2*',       # pulled in by testtools
        '*/mimeparse*',        # pulled in by testtools
        '*/mock*',
        '*/pbr*',              # pulled in by testtools
        '*/pkg_resources*',    # pulled in by django
        '*/pypy*',
        '*/pytz*',             # pulled in by django
        '*/six*',              # pulled in by testtools
        '*/termstyle*',
        '*/test*',
        '*/traceback2*',       # pulled in by testtools
        '*/unittest2*',        # pulled in by testtools
        '*Python.framework*',  # OS X system python
        '*site-packages*',     # System python for other OS's
        tempfile.gettempdir() + '*',
    ]
    if new_args.clear_omit:
        omit_patterns = []

    if new_args.omit_patterns:
        omit_patterns.extend(new_args.omit_patterns.split(','))
    new_args.omit_patterns = omit_patterns

    if new_args.include_patterns:
        new_args.include_patterns = new_args.include_patterns.split(',')
    else:
        new_args.include_patterns = []

    if new_args.quiet_coverage or (type(new_args.cov_config_file) == str):
        new_args.run_coverage = True

    if new_args.minimum_coverage != None:
        new_args.run_coverage = True

    if new_args.run_coverage:
        if not testing:
            cov = coverage.coverage(data_file='.coverage', omit=omit_patterns,
                                    include=new_args.include_patterns,
                                    config_file = new_args.cov_config_file)
            cov.start()
        new_args.cov = cov

    return new_args
Beispiel #8
0
def mergeConfig(args, testing=False, coverage_testing=False): # pragma: no cover
    """
    I take in a namespace created by the ArgumentParser in cmdline.main() and
    merge in options from configuration files.  The config items only replace
    argument items that are set to default value.

    Returns: I return a new argparse.Namespace, adding members:
        shouldExit = default False
        exitCode   = default 0
        omit       = omit settings converted to list and extended
        cov        = coverage object default None
    """
    config = getConfig(args.config)
    new_args = copy.deepcopy(default_args) # Default by default!

    for name, args_value in dict(args._get_kwargs()).items():
        # Config options overwrite default options
        config_getter = None
        if name in ['html', 'termcolor', 'notermcolor', 'help', 'logging',
                'version', 'run_coverage', 'options', 'completions',
                'completion_file']:
            config_getter = config.getboolean
        elif name in ['subprocesses', 'debug', 'verbose']:
            config_getter = config.getint
        elif name in ['omit']:
            config_getter = config.get
        elif name in ['targets', 'help', 'config']:
            pass # Some options only make sense coming on the command-line.
        elif name in ['store_opt', 'parser']:
            pass # These are convenience objects, not actual settings
        else:
            raise NotImplementedError(name)

        if config_getter:
            try:
                config_value = config_getter('green', name.replace('_','-'))
                setattr(new_args, name, config_value)
            except (configparser.NoSectionError, configparser.NoOptionError):
                pass

        # Command-line values overwrite defaults and config values
        if args_value != getattr(default_args, name):
            setattr(new_args, name, args_value)

    new_args.shouldExit = False
    new_args.exitCode = 0
    new_args.cov = None

    # Help?
    if new_args.help: # pragma: no cover
        new_args.parser.print_help()
        new_args.shouldExit = True
        return new_args

    # Did we just print the version?
    if new_args.version:
        from green.version import pretty_version
        sys.stdout.write(pretty_version()+'\n')
        new_args.shouldExit = True
        return new_args

    # Handle logging options
    if new_args.debug:
        logging.basicConfig(
                level=logging.DEBUG,
                format="%(asctime)s %(levelname)9s %(message)s",
                datefmt="%Y-%m-%d %H:%M:%S")
    elif not new_args.logging:
        logging.basicConfig(filename=os.devnull)

    # These options both disable termcolor
    if new_args.html or new_args.notermcolor:
        new_args.termcolor = False

    # Coverage.  We must enable it here because we cannot cover module-level
    # code after it is imported, and this is the earliest place we can turn on
    # coverage.
    omit = []
    if new_args.omit:
        omit = new_args.omit.split(',')
    else:
        omit = [
            '*/test*',
            '*/termstyle*',
            '*/colorama*',
            '*/mock*',
            '*/django/*',
            '*/pytz*',          # pulled in by django
            '*/pkg_resources*', # pulled in by django
            '*/pypy*',
            tempfile.gettempdir() + '*']
        if 'green' not in new_args.targets and (
                False in [t.startswith('green.') for t in new_args.targets]):
            omit.extend([
            '*Python.framework*',
            '*site-packages*'])
    new_args.omit = omit

    if new_args.run_coverage:
        if not coverage:
            print(
                "Fatal: The 'coverage' module is not installed.  Have you "
                "run 'pip install coverage' ???")
            args.shouldExit = True
            args.exitCode = 3
            return args
        if (not testing) or coverage_testing:
            cov = coverage.coverage(data_file='.coverage', omit=omit)
            cov.start()
        new_args.cov = cov

    return new_args
Beispiel #9
0
def mergeConfig(args, testing=False): # pragma: no cover
    """
    I take in a namespace created by the ArgumentParser in cmdline.main() and
    merge in options from configuration files.  The config items only replace
    argument items that are set to default value.

    Returns: I return a new argparse.Namespace, adding members:
        shouldExit       = default False
        exitCode         = default 0
        include patterns = include-patterns setting converted to list.
        omit_patterns    = omit-patterns settings converted to list and
                           extended, taking clear-omit into account.
        cov              = coverage object default None
    """
    config = getConfig(getattr(args, 'config', default_args.config))
    new_args = copy.deepcopy(default_args) # Default by default!

    for name, default_value in dict(default_args._get_kwargs()).items():
        # Config options overwrite default options
        config_getter = None
        if name in ['termcolor', 'notermcolor', 'allow_stdout', 'quiet_stdout',
                'help', 'logging', 'version', 'failfast', 'run_coverage',
                'options', 'completions', 'completion_file', 'clear_omit',
                'no_skip_report', 'disable_windows']:
            config_getter = config.getboolean
        elif name in ['processes', 'debug', 'verbose']:
            config_getter = config.getint
        elif name in ['file_pattern', 'finalizer', 'initializer',
            'include_patterns', 'omit_patterns', 'warnings', 'test_pattern']:
            config_getter = config.get
        elif name in ['targets', 'help', 'config']:
            pass # Some options only make sense coming on the command-line.
        elif name in ['store_opt', 'parser']:
            pass # These are convenience objects, not actual settings
        else:
            raise NotImplementedError(name)

        if config_getter:
            try:
                config_value = config_getter('green', name.replace('_','-'))
                setattr(new_args, name, config_value)
            except (configparser.NoSectionError, configparser.NoOptionError):
                pass

        # Command-line values overwrite defaults and config values when
        # specified
        args_value = getattr(args, name, 'unspecified')
        if args_value != 'unspecified':
            setattr(new_args, name, args_value)

    new_args.shouldExit = False
    new_args.exitCode = 0
    new_args.cov = None

    # Help?
    if new_args.help: # pragma: no cover
        new_args.parser.print_help()
        new_args.shouldExit = True
        return new_args

    # Did we just print the version?
    if new_args.version:
        from green.version import pretty_version
        sys.stdout.write(pretty_version()+'\n')
        new_args.shouldExit = True
        return new_args

    # Handle logging options
    if new_args.debug:
        logging.basicConfig(
                level=logging.DEBUG,
                format="%(asctime)s %(levelname)9s %(message)s",
                datefmt="%Y-%m-%d %H:%M:%S")
    elif not new_args.logging:
        logging.basicConfig(filename=os.devnull)

    # Disable termcolor?
    if new_args.notermcolor:
        new_args.termcolor = False

    # Coverage.  We must enable it here because we cannot cover module-level
    # code after it is imported, and this is the earliest place we can turn on
    # coverage.
    omit_patterns = [
        '*/argparse*',
        '*/colorama*',
        '*/django/*',
        '*/distutils*',       # Gets pulled in on Travis-CI CPython
        '*/extras*',          # pulled in by testtools
        '*/linecache2*',      # pulled in by testtools
        '*/mimeparse*',       # pulled in by testtools
        '*/mock*',
        '*/pbr*',             # pulled in by testtools
        '*/pkg_resources*',   # pulled in by django
        '*/pypy*',
        '*/pytz*',            # pulled in by django
        '*/six*',             # pulled in by testtools
        '*/termstyle*',
        '*/test*',
        '*/traceback2*',      # pulled in by testtools
        '*/unittest2*',       # pulled in by testtools
        '*Python.framework*', # OS X system python
        '*site-packages*',    # System python for other OS's
        tempfile.gettempdir() + '*',
    ]
    if new_args.clear_omit:
        omit_patterns = []
    if new_args.omit_patterns:
        omit_patterns.extend(new_args.omit_patterns.split(','))
    new_args.omit_patterns = omit_patterns

    if new_args.include_patterns:
        new_args.include_patterns = new_args.include_patterns.split(',')
    else:
        new_args.include_patterns = []

    if new_args.run_coverage:
        if not coverage:
            print(
                "Fatal: The 'coverage' module is not installed.  Have you "
                "run 'pip install coverage' ???")
            args.shouldExit = True
            args.exitCode = 3
            return args
        if not testing:
            cov = coverage.coverage(data_file='.coverage', omit=omit_patterns,
                    include=new_args.include_patterns)
            cov.start()
        new_args.cov = cov

    return new_args
Beispiel #10
0
def main(testing=False, coverage_testing=False):
    parser = argparse.ArgumentParser(
            add_help=False,
            description="Green is a clean, colorful test runner for Python unit tests.")
    target_args = parser.add_argument_group("Target Specification")
    target_args.add_argument('targets', action='store', nargs='*', default=['.'],
        help=("""Targets to test.  If blank, then discover all testcases in the
        current directory tree.  Can be a directory (or package), file (or
        module), or fully-qualified 'dotted name' like
        proj.tests.test_things.TestStuff.  If a directory (or package)
        is specified, then we will attempt to discover all tests under the
        directory (even if the directory is a package and the tests would not
        be accessible through the package's scope).  In all other cases,
        only tests accessible from introspection of the object will be
        loaded."""))
    concurrency_args = parser.add_argument_group("Concurrency Options")
    concurrency_args.add_argument('-s', '--subprocesses', action='store',
            type=int, default=1, metavar='NUM',
            help="Number of subprocesses to use to run tests.  Note that your "
            "tests need to be written to avoid using the same resources (temp "
            "files, sockets, ports, etc.) for the multi-process mode to work "
            "well. Default is 1, meaning try to autodetect the number of CPUs "
            "in the system.  1 will disable using subprocesses.  Note that for "
            "trivial tests (tests that take < 1ms), running everything in a "
            "single process may be faster.")
    format_args = parser.add_argument_group("Format Options")
    format_args.add_argument('-m', '--html', action='store_true', default=False,
        help="HTML5 format.  Overrides terminal color options if specified.")
    format_args.add_argument('-t', '--termcolor', action='store_true',
        default=None,
        help="Force terminal colors on.  Default is to autodetect.")
    format_args.add_argument('-T', '--notermcolor', action='store_true',
        default=None,
        help="Force terminal colors off.  Default is to autodetect.")
    out_args = parser.add_argument_group("Output Options")
    out_args.add_argument('-d', '--debug', action='count', default=0,
        help=("Enable internal debugging statements.  Implies --logging.  Can "
        "be specified up to three times for more debug output."))
    out_args.add_argument('-h', '--help', action='store_true', default=False,
        help="Show this help message and exit.")
    out_args.add_argument('-l', '--logging', action='store_true', default=False,
        help="Don't configure the root logger to redirect to /dev/null")
    out_args.add_argument('-V', '--version', action='store_true', default=False,
        help="Print the version of Green and Python and exit.")
    out_args.add_argument('-v', '--verbose', action='count', default=1,
        help=("Verbose. Can be specified up to three times for more verbosity. "
        "Recommended levels are -v and -vv."))
    cov_args = parser.add_argument_group(
        "Coverage Options ({})".format(coverage_version))
    cov_args.add_argument('-r', '--run-coverage', action='store_true',
        default=False,
        help=("Produce coverage output."))
    cov_args.add_argument('-o', '--omit', action='store', default=None,
        metavar='PATTERN',
        help=("Comma-separated file-patterns to omit from coverage.  Default "
            "is something like '*/test*,*/termstyle*,*/mock*,*(temp "
            "dir)*,*(python system packages)*'"))
    args = parser.parse_args()

    # Clear out all the passed-in-options just in case someone tries to run a
    # test that assumes sys.argv is clean.  I can't guess at the script name
    # that they want, though, so we'll just leave ours.
    sys.argv = sys.argv[:1]

    # Help?
    if args.help: # pragma: no cover
        parser.print_help()
        return 0

    # Just print version and exit?
    if args.version:
        from green.version import pretty_version
        sys.stdout.write(pretty_version()+'\n')
        return 0

    # Handle logging options
    if args.debug:
        logging.basicConfig(
                level=logging.DEBUG,
                format="%(asctime)s %(levelname)9s %(message)s")
    elif not args.logging:
        logging.basicConfig(filename=os.devnull)

    # These options both disable termcolor
    if args.html or args.notermcolor:
        args.termcolor = False

    # Coverage?
    omit = []
    if args.run_coverage:
        if args.omit:
            omit = args.omit.split(',')
        else:
            omit = [
                '*/test*',
                '*/termstyle*',
                '*/mock*',
                tempfile.gettempdir() + '*']
            if 'green' not in args.targets and (False in [t.startswith('green.') for t in args.targets]):
                omit.extend([
                '*Python.framework*',
                '*site-packages*'])
        if not coverage:
            sys.stderr.write(
                "Fatal: The 'coverage' module is not installed.  Have you "
                "run 'pip install coverage'???")
            return 3
        if (not testing) or coverage_testing:
            cov = coverage.coverage(data_file='.coverage', omit=omit)
            cov.start()


    # Set up our various main objects
    from green.loader import getTests
    from green.runner import GreenTestRunner
    from green.output import GreenStream
    import green.output
    if args.debug:
        green.output.debug_level = args.debug

    stream = GreenStream(sys.stderr, html = args.html)
    runner = GreenTestRunner(verbosity = args.verbose, stream = stream,
            termcolor=args.termcolor, subprocesses=args.subprocesses,
            run_coverage=args.run_coverage, omit=omit)

    # Discover/Load the TestSuite
    tests = getTests(args.targets)

    # We didn't even load 0 tests...
    if not tests:
        logging.debug(
            "No test loading attempts succeeded.  Created an empty test suite.")
        tests = unittest.suite.TestSuite()

    # Actually run the tests
    if testing:
        result = lambda: None
        result.wasSuccessful = lambda: 0
    else:
        result = runner.run(tests) # pragma: no cover

    if args.run_coverage and ((not testing) or coverage_testing):
        stream.writeln()
        cov.stop()
        cov.save()
        cov.combine()
        cov.save()
        cov.report(file=stream, omit=omit)
    return(int(not result.wasSuccessful()))
Beispiel #11
0
def mergeConfig(args, testing=False):  # pragma: no cover
    """
    I take in a namespace created by the ArgumentParser in cmdline.main() and
    merge in options from configuration files.  The config items only replace
    argument items that are set to default value.

    Returns: I return a new argparse.Namespace, adding members:
        shouldExit    = default False
        exitCode      = default 0
        omit_patterns = omit-patterns settings converted to list and extended,
                        taking clear-omit into account.
        cov           = coverage object default None
    """
    config = getConfig(getattr(args, "config", default_args.config))
    new_args = copy.deepcopy(default_args)  # Default by default!

    for name, default_value in dict(default_args._get_kwargs()).items():
        # Config options overwrite default options
        config_getter = None
        if name in [
            "termcolor",
            "notermcolor",
            "allow_stdout",
            "help",
            "logging",
            "version",
            "failfast",
            "run_coverage",
            "options",
            "completions",
            "completion_file",
            "clear_omit",
            "no_skip_report",
        ]:
            config_getter = config.getboolean
        elif name in ["processes", "debug", "verbose"]:
            config_getter = config.getint
        elif name in ["file_pattern", "finalizer", "initializer", "omit_patterns", "warnings", "test_pattern"]:
            config_getter = config.get
        elif name in ["targets", "help", "config"]:
            pass  # Some options only make sense coming on the command-line.
        elif name in ["store_opt", "parser"]:
            pass  # These are convenience objects, not actual settings
        else:
            raise NotImplementedError(name)

        if config_getter:
            try:
                config_value = config_getter("green", name.replace("_", "-"))
                setattr(new_args, name, config_value)
            except (configparser.NoSectionError, configparser.NoOptionError):
                pass

        # Command-line values overwrite defaults and config values when
        # specified
        args_value = getattr(args, name, "unspecified")
        if args_value != "unspecified":
            setattr(new_args, name, args_value)

    new_args.shouldExit = False
    new_args.exitCode = 0
    new_args.cov = None

    # Help?
    if new_args.help:  # pragma: no cover
        new_args.parser.print_help()
        new_args.shouldExit = True
        return new_args

    # Did we just print the version?
    if new_args.version:
        from green.version import pretty_version

        sys.stdout.write(pretty_version() + "\n")
        new_args.shouldExit = True
        return new_args

    # Handle logging options
    if new_args.debug:
        logging.basicConfig(
            level=logging.DEBUG, format="%(asctime)s %(levelname)9s %(message)s", datefmt="%Y-%m-%d %H:%M:%S"
        )
    elif not new_args.logging:
        logging.basicConfig(filename=os.devnull)

    # Disable termcolor?
    if new_args.notermcolor:
        new_args.termcolor = False

    # Coverage.  We must enable it here because we cannot cover module-level
    # code after it is imported, and this is the earliest place we can turn on
    # coverage.
    omit_patterns = [
        "*/argparse*",
        "*/colorama*",
        "*/django/*",
        "*/distutils*",  # Gets pulled in on Travis-CI CPython
        "*/extras*",  # pulled in by testtools
        "*/linecache2*",  # pulled in by testtools
        "*/mimeparse*",  # pulled in by testtools
        "*/mock*",
        "*/pbr*",  # pulled in by testtools
        "*/pkg_resources*",  # pulled in by django
        "*/pypy*",
        "*/pytz*",  # pulled in by django
        "*/six*",  # pulled in by testtools
        "*/termstyle*",
        "*/test*",
        "*/traceback2*",  # pulled in by testtools
        "*/unittest2*",  # pulled in by testtools
        "*Python.framework*",  # OS X system python
        "*site-packages*",  # System python for other OS's
        tempfile.gettempdir() + "*",
    ]
    if new_args.clear_omit:
        omit_patterns = []
    if new_args.omit_patterns:
        omit_patterns.extend(new_args.omit_patterns.split(","))
    new_args.omit_patterns = omit_patterns

    if new_args.run_coverage:
        if not coverage:
            print("Fatal: The 'coverage' module is not installed.  Have you " "run 'pip install coverage' ???")
            args.shouldExit = True
            args.exitCode = 3
            return args
        if not testing:
            cov = coverage.coverage(data_file=".coverage", omit=omit_patterns)
            cov.start()
        new_args.cov = cov

    return new_args
Beispiel #12
0
def mergeConfig(args, testing=False):  # pragma: no cover
    """
    I take in a namespace created by the ArgumentParser in cmdline.main() and
    merge in options from configuration files.  The config items only replace
    argument items that are set to default value.

    Returns: I return a new argparse.Namespace, adding members:
        shouldExit       = default False
        exitCode         = default 0
        include patterns = include-patterns setting converted to list.
        omit_patterns    = omit-patterns settings converted to list and
                           extended, taking clear-omit into account.
        cov              = coverage object default None
    """
    config = getConfig(getattr(args, "config", default_args.config))
    new_args = copy.deepcopy(default_args)  # Default by default!

    for name, default_value in dict(default_args._get_kwargs()).items():
        # Config options overwrite default options
        config_getter = None
        if name in [
            "termcolor",
            "notermcolor",
            "allow_stdout",
            "quiet_stdout",
            "help",
            "logging",
            "version",
            "disable_unidecode",
            "failfast",
            "run_coverage",
            "options",
            "completions",
            "completion_file",
            "clear_omit",
            "no_skip_report",
            "no_tracebacks",
            "disable_windows",
            "quiet_coverage",
        ]:
            config_getter = config.getboolean
        elif name in ["processes", "debug", "verbose", "minimum_coverage"]:
            config_getter = config.getint
        elif name in [
            "file_pattern",
            "finalizer",
            "initializer",
            "cov_config_file",
            "include_patterns",
            "omit_patterns",
            "warnings",
            "test_pattern",
            "junit_report",
        ]:
            config_getter = config.get
        elif name in ["targets", "help", "config"]:
            pass  # Some options only make sense coming on the command-line.
        elif name in ["store_opt", "parser"]:
            pass  # These are convenience objects, not actual settings
        else:
            raise NotImplementedError(name)

        if config_getter:
            try:
                config_value = config_getter("green", name.replace("_", "-"))
                setattr(new_args, name, config_value)
            except (configparser.NoSectionError, configparser.NoOptionError):
                pass

        # Command-line values overwrite defaults and config values when
        # specified
        args_value = getattr(args, name, "unspecified")
        if args_value != "unspecified":
            setattr(new_args, name, args_value)

    new_args.shouldExit = False
    new_args.exitCode = 0
    new_args.cov = None

    # Help?
    if new_args.help:  # pragma: no cover
        new_args.parser.print_help()
        new_args.shouldExit = True
        return new_args

    # Did we just print the version?
    if new_args.version:
        from green.version import pretty_version

        sys.stdout.write(pretty_version() + "\n")
        new_args.shouldExit = True
        return new_args

    # Handle logging options
    if new_args.debug:
        logging.basicConfig(
            level=logging.DEBUG,
            format="%(asctime)s %(levelname)9s %(message)s",
            datefmt="%Y-%m-%d %H:%M:%S",
        )
    elif not new_args.logging:
        logging.basicConfig(filename=os.devnull)

    # Disable termcolor?
    if new_args.notermcolor:
        new_args.termcolor = False

    # Coverage.  We must enable it here because we cannot cover module-level
    # code after it is imported, and this is the earliest place we can turn on
    # coverage.
    omit_patterns = [
        "*/argparse*",
        "*/colorama*",
        "*/django/*",
        "*/distutils*",  # Gets pulled in on Travis-CI CPython
        "*/extras*",  # pulled in by testtools
        "*/linecache2*",  # pulled in by testtools
        "*/mimeparse*",  # pulled in by testtools
        "*/mock*",
        "*/pbr*",  # pulled in by testtools
        "*/pkg_resources*",  # pulled in by django
        "*/pypy*",
        "*/pytz*",  # pulled in by django
        "*/six*",  # pulled in by testtools
        "*/termstyle*",
        "*/test*",
        "*/traceback2*",  # pulled in by testtools
        "*/unittest2*",  # pulled in by testtools
        "*Python.framework*",  # OS X system python
        "*site-packages*",  # System python for other OS's
        tempfile.gettempdir() + "*",
    ]
    if new_args.clear_omit:
        omit_patterns = []

    if new_args.omit_patterns:
        omit_patterns.extend(new_args.omit_patterns.split(","))
    new_args.omit_patterns = omit_patterns

    if new_args.include_patterns:
        new_args.include_patterns = new_args.include_patterns.split(",")
    else:
        new_args.include_patterns = []

    if new_args.quiet_coverage or (type(new_args.cov_config_file) == str):
        new_args.run_coverage = True

    if new_args.minimum_coverage != None:
        new_args.run_coverage = True

    if new_args.run_coverage:
        if not testing:
            cov = coverage.coverage(
                data_file=".coverage",
                omit=omit_patterns,
                include=new_args.include_patterns,
                config_file=new_args.cov_config_file,
            )
            cov.start()
        new_args.cov = cov

    return new_args