def execute_test(site, test):
    import twill.commands as commands
    #Avoid circular import
    from kong.models import TestResult
    twill_script = test.render(site)
    content = ''
    old_err = sys.stderr
    new_err = StringIO.StringIO()
    commands.ERR = new_err

    now = datetime.datetime.now()
    try:
        if getattr(settings, 'KONG_RESET_BROWSER', False):
            execute_string(twill_script, no_reset = False)
        else:
            execute_string(twill_script)
        succeeded = True
        content = new_err.getvalue().strip()
    except Exception, e:
        succeeded = False
        content = new_err.getvalue().strip() + "\n\nException:\n\n" + str(e)

    end = datetime.datetime.now()
    duration = now - end
    duration = duration.microseconds
    commands.ERR = old_err
    result = TestResult.objects.create(site=site,
                                       test=test,
                                       succeeded=succeeded,
                                       duration=duration,
                                       content=content)

    if result.notification_needed and result.failed:
        _send_error(site, test, content)
    if result.notification_needed and result.succeeded:
        _send_recovery(site, test, content)

    return succeeded
dataset/ETHPy150Open ericholscher/django-kong/kong/utils.py/execute_test/swapped operands of `-`