def test_run_tests_in_parallel_returns_test_result_class():
    def do_nothing(cls):
        pass
    test_suite = [fixture_for(do_nothing)]
    runner = TestRunner(test_suite = test_suite, working_threads = 5)
    result = runner.run()
    assert isinstance(result, TestResult)
def test_run_tests_in_parallel_returns_failure_and_error_message_from_the_test_if_it_fails():
    def do_fail(cls):
        assert True == False, "True can never be False"
    test_suite = [fixture_for(do_fail)]
    runner = TestRunner(test_suite = test_suite, working_threads = 5)
    result = runner.run()
    assert result.results[0][1] == TestResult.Failure
    assert "True can never be False" in result.results[0][2], "Error message returned is different from expected one: %s" % result.results[0][2]
def test_run_tests_in_parallel_returns_success_result_from_the_test_if_it_passes():
    def do_nothing(cls):
        pass
    test_suite = [fixture_for(do_nothing)]
    runner = TestRunner(test_suite = test_suite, working_threads = 5)
    result = runner.run()
    assert result.results is not None
    assert result.results[0][1] == TestResult.Success
def test_run_tests_in_parallel_returns_something():
    def do_nothing(cls):
        pass
        
    test_suite = [fixture_for(do_nothing)]
    runner = TestRunner(test_suite = test_suite, working_threads = 5)
    result = runner.run()
    assert result is not None
def test_running_tests_in_parallel_return_results():
    parser = TestParser(tests_dir = join(test_path, "samples"))

    parser.parse()
    tests = parser.tests

    runner = TestRunner(test_suite = tests, working_threads = 5)
    start_date = datetime.now()
    result = runner.run()
    
    assert len(result.results) == 1
    assert result.results[0][1] == TestResult.Success, \
                        "The result should've been successful but was %s" % ", ".join(result.results[0])
def test_running_tests_in_parallel_takes_a_proper_amount_of_time():
    def do_sleep(cls):
        time.sleep(2)
    
    test_fixture = fixture_for(do_sleep)
    test_suite = (test_fixture, test_fixture, test_fixture, test_fixture, test_fixture, test_fixture)
    
    #given 6 tests and 5 working threads the test should take ten seconds
    runner = TestRunner(test_suite = test_suite, working_threads = 5)
    start_date = datetime.now()
    result = runner.run()

    period = datetime.now() - start_date
    if period.seconds <= 3 or period.seconds >= 5:
        raise ValueError("The test should have finished in ~10 seconds and finished in %d." % period.seconds)
Example #7
0
def main():
    """ Main function - parses args and runs action """
    parser = optparse.OptionParser(usage="%prog or type %prog -h (--help) for help", description=__doc__, version="%prog" + __revision__)
    parser.add_option("-d", "--dir", dest="dir", default=None, help="Directory to run the tests in. If none specified it runs in the current directory.")
    parser.add_option("-p", "--pattern", dest="pattern", default="*.py", help="Pattern of files to use for retrieving tests.")
    parser.add_option("-r", "--recursive", dest="recursive", default="true", help="Specifies whether sub-folders of the 'dir' parameter should be parsed as well. Defaults to 'true' (set to 'false' to parse only the tests in the specified dir)")
    parser.add_option("-t", "--threads", dest="threads", default="5", help="Number of threads to run tests with [default: %default].")

    (options, args) = parser.parse_args()

    tests_dir = options.dir and abspath(options.dir) or abspath(os.curdir)

    start_time = time.time()

    parser = TestParser(tests_dir=tests_dir, pattern = options.pattern)
    parser.parse()
    
    test_suite = parser.tests
    
    if not test_suite:
        print "No tests found under %s with the %s pattern" % (tests_dir, options.pattern)
        sys.exit(0)
    
    runner = TestRunner(test_suite=test_suite, working_threads=int(options.threads))
    
    def print_success(name, test):
        sys.stdout.write(".")
        sys.stdout.flush()
    def print_failure(name, test, message):
        sys.stdout.write("F")
        sys.stdout.flush()

    runner.test_successful = print_success
    runner.test_failed = print_failure
        
    results = runner.run()

    print

    print_tests(results)

    print "-" * 80
    print "Test run successful"
    show_time(start_time)
    print "-" * 80

    sys.exit(0)