예제 #1
0
def main():
    """
    Execute the nose test runner.

    Drop privileges and alter the system argument to remove the
    userid and group id arguments that are only required for the test.
    """
    if len(sys.argv) < 2:
        print (
            u'Run the test suite using drop privileges username as first '
            u'arguments. Use "-" if you do not want elevated mode.')
        sys.exit(1)

    # Delay import after coverage is started.
    from chevah.empirical.nose_memory_usage import MemoryUsage
    from chevah.empirical.nose_test_timer import TestTimer
    from chevah.empirical.nose_run_reporter import RunReporter

    from chevah.empirical import EmpiricalTestCase


    drop_user = sys.argv[1]
    EmpiricalTestCase.initialize(drop_user=drop_user)
    EmpiricalTestCase.dropPrivileges()

    new_argv = ['chevah-test-runner']
    new_argv.extend(sys.argv[2:])
    sys.argv = new_argv
    plugins = [
        TestTimer(),
        RunReporter(),
        MemoryUsage(),
        ]
    try:
        nose_main(addplugins=plugins)
    except SystemExit, error:
        if cov:
            cov.stop()
            cov.save()
        import threading
        print "Max RSS: %s" % EmpiricalTestCase.getPeakMemoryUsage()
        threads = threading.enumerate()
        if len(threads) < 2:
            # No running threads, other than main so we can exit as normal.
            sys.exit(error.code)
        else:
            print "There are still active threads: %s" % threads

            # We do a brute force exit here, since sys.exit will wait for
            # unjoined threads.
            # We have to do some manual work to compensate for skipping sys.exit()
            sys.exitfunc()
            # Don't forget to flush the toilet.
            sys.stdout.flush()
            sys.stderr.flush()
            os._exit(error.code)
예제 #2
0
def setup_package():
    # Don't run these tests if we can not access privileged OS part.
    if not should_run_elevated_test():
        raise EmpiricalTestCase.skipTest()

    # Initialize the testing OS.
    try:
        setup_access_control(users=TEST_USERS, groups=TEST_GROUPS)
    except:  # pragma: no cover
        # Report some error if setup fails and rollback.
        import traceback
        error = traceback.format_exc()
        try:
            teardown_access_control(users=TEST_USERS, groups=TEST_GROUPS)
        except:
            pass
        raise AssertionError(
            'Failed to initialize system accounts.\n\n%s' % (error))
예제 #3
0
 def getPeakMemoryUsage(self):
     """
     Method to prevent circular import.
     """
     from chevah.empirical import EmpiricalTestCase
     return EmpiricalTestCase.getPeakMemoryUsage()