Example #1
0
def main(tests=None, **kwargs):
    parser = make_parser(**kwargs)
    options, args = parser.parse_args()

    # When run as a console script (i.e. ``attest``), the CWD isn't
    # ``sys.path[0]``, but it should be. It's important to do this early in
    # case custom reporters are being used that make the assumption that CWD is
    # on ``sys.path``.
    cwd = os.getcwd()
    if sys.path[0] not in ('', cwd):
        sys.path.insert(0, cwd)

    if options.list_reporters:
        for reporter in get_all_reporters():
            print reporter
        return

    opts = parse_options(args)
    reporter = get_reporter_by_name(options.reporter)(**opts)

    if not tests:
        names = [arg for arg in args if '=' not in arg]
        if not names:
            names = [
                name for name in os.listdir('.')
                if path.isfile('%s/__init__.py' % name)
            ]

        if options.native_assert:
            tests = Tests(names)
        else:
            with AssertImportHook():
                tests = Tests(names)

    def run():
        tests.run(reporter,
                  full_tracebacks=options.full_tracebacks,
                  fail_fast=options.fail_fast,
                  debugger=options.debugger,
                  no_capture=options.no_capture,
                  keyboard_interrupt=options.keyboard_interrupt)

    if options.profile:
        filename = options.profile
        import cProfile
        cProfile.runctx('run()', globals(), locals(), filename)
        print 'Wrote profiling results to %r.' % (filename, )
    else:
        run()
Example #2
0
def main(tests=None, **kwargs):
    parser = make_parser(**kwargs)
    options, args = parser.parse_args()

    # When run as a console script (i.e. ``attest``), the CWD isn't
    # ``sys.path[0]``, but it should be. It's important to do this early in
    # case custom reporters are being used that make the assumption that CWD is
    # on ``sys.path``.
    cwd = os.getcwd()
    if sys.path[0] not in ('', cwd):
        sys.path.insert(0, cwd)

    if options.list_reporters:
        for reporter in get_all_reporters():
            print reporter
        return

    opts = parse_options(args)
    reporter = get_reporter_by_name(options.reporter)(**opts)

    if not tests:
        names = [arg for arg in args if '=' not in arg]
        if not names:
            names = [name for name in os.listdir('.')
                          if path.isfile('%s/__init__.py' % name)]

        if options.native_assert:
            tests = Tests(names)
        else:
            with AssertImportHook():
                tests = Tests(names)

    def run():
        tests.run(reporter, full_tracebacks=options.full_tracebacks,
                            fail_fast=options.fail_fast,
                            debugger=options.debugger,
                            no_capture=options.no_capture,
                            keyboard_interrupt=options.keyboard_interrupt)

    if options.profile:
        filename = options.profile
        import cProfile
        cProfile.runctx('run()', globals(), locals(), filename)
        print 'Wrote profiling results to %r.' % (filename,)
    else:
        run()
Example #3
0
File: run.py Project: JNRowe/attest
def main(tests=None, **kwargs):
    parser = make_parser(**kwargs)
    options, args = parser.parse_args()

    if options.list_reporters:
        for reporter in get_all_reporters():
            print reporter
        return

    opts = parse_options(args)
    reporter = get_reporter_by_name(options.reporter)(**opts)

    if not tests:
        sys.path.insert(0, os.getcwd())
        names = [arg for arg in args if '=' not in arg]
        if not names:
            names = [name for name in os.listdir('.')
                          if path.isfile('%s/__init__.py' % name)]

        if options.native_assert:
            tests = Tests(names)
        else:
            with AssertImportHook():
                tests = Tests(names)

    def run():
        tests.run(reporter, full_tracebacks=options.full_tracebacks,
                            fail_fast=options.fail_fast,
                            debugger=options.debugger,
                            no_capture=options.no_capture,
                            keyboard_interrupt=options.keyboard_interrupt)

    if options.profile:
        filename = options.profile
        import cProfile
        cProfile.runctx('run()', globals(), locals(), filename)
        print 'Wrote profiling results to %r.' % (filename,)
    else:
        run()