def runtest_inner(test, verbose, quiet, test_times,
                  testdir=None, huntrleaks=False, junit_xml_dir=None):
    test_support.unload(test)
    if not testdir:
        testdir = findtestdir()
    if verbose:
        capture_stdout = None
    else:
        capture_stdout = cStringIO.StringIO()

    from test.junit_xml import Tee, write_direct_test
    try:
        save_stdout = sys.stdout

        indirect_test = None
        if junit_xml_dir:
            save_stderr = sys.stderr
            sys.stdout = stdout = Tee(sys.stdout)
            sys.stderr = stderr = Tee(sys.stderr)
        try:
            if capture_stdout:
                sys.stdout = capture_stdout
            if test.startswith('test.'):
                abstest = test
            else:
                # Always import it from the test package
                abstest = 'test.' + test
            start_time = time.time()
            the_package = __import__(abstest, globals(), locals(), [])
            the_module = getattr(the_package, test)
            # Old tests run to completion simply as a side-effect of
            # being imported.  For tests based on unittest or doctest,
            # explicitly invoke their test_main() function (if it exists).
            indirect_test = getattr(the_module, "test_main", None)
            test_time = None
            if indirect_test is not None:
                indirect_test()
            elif junit_xml_dir:
                test_time = time.time() - start_time
                write_direct_test(junit_xml_dir, abstest, test_time,
                                  stdout=stdout.getvalue(),
                                  stderr=stderr.getvalue())
            if huntrleaks:
                dash_R(the_module, test, indirect_test, huntrleaks)
            if test_time is None:
                test_time = time.time() - start_time
            test_times.append((test_time, test))
        finally:
            sys.stdout = save_stdout
            if junit_xml_dir:
                sys.stderr = save_stderr
                test_time = time.time() - start_time
    except test_support.ResourceDenied, msg:
        if not quiet:
            print test, "skipped --", msg
            sys.stdout.flush()
        if junit_xml_dir:
            write_direct_test(junit_xml_dir, abstest, test_time,
                              'skipped', sys.exc_info(),
                              stdout=stdout.getvalue(),
                              stderr=stderr.getvalue())
        return -2
    except (__HOLE__, unittest.SkipTest), msg:
        if not quiet:
            print test, "skipped --", msg
            sys.stdout.flush()
        if junit_xml_dir:
            write_direct_test(junit_xml_dir, abstest, test_time,
                              'skipped', sys.exc_info(),
                              stdout=stdout.getvalue(),
                              stderr=stderr.getvalue())
        return -1
    except KeyboardInterrupt:
        raise
    except test_support.TestFailed, msg:
        print "test", test, "failed --", msg
        sys.stdout.flush()
        if junit_xml_dir and indirect_test is None:
            write_direct_test(junit_xml_dir, abstest, test_time,
                              'failure', sys.exc_info(),
                              stdout=stdout.getvalue(),
                              stderr=stderr.getvalue())
        return 0
    except:
        type, value = sys.exc_info()[:2]
        print "test", test, "crashed --", str(type) + ":", value
        sys.stdout.flush()
        if verbose:
            traceback.print_exc(file=sys.stdout)
            sys.stdout.flush()
        if junit_xml_dir and indirect_test is None:
            write_direct_test(junit_xml_dir, abstest, test_time,
                              'error', sys.exc_info(),
                              stdout=stdout.getvalue(),
                              stderr=stderr.getvalue())
        return 0
    else:
        # Except in verbose mode, tests should not print anything
        if verbose or huntrleaks:
            return 1
        output = capture_stdout.getvalue()
        if not output:
            return 1
        print "test", test, "produced unexpected output:"
        print "*" * 70
        print output
        print "*" * 70
        sys.stdout.flush()
        return 0
dataset/ETHPy150Open azoft-dev-team/imagrium/env/Lib/test/regrtest.py/runtest_inner