예제 #1
0
파일: test.py 프로젝트: jererc/tracy-py
def run():
    delta = timedelta(hours=Settings.get_settings('tests_delta') or 12)
    if TestInfo.find_one({
            'finished': {'$gte': datetime.utcnow() - delta},
            }):
        return

    tests_info = {
        'started': datetime.utcnow(),
        'tests_run': 0,
        'errors': 0,
        'failures': 0,
        'skipped': 0,
        }
    files = Settings.get_settings('tests_files') or []
    for file in files:
        results = run_tests(file)
        ids = []
        for type in ('errors', 'failures', 'skipped'):
            for res in getattr(results, type):
                info = get_info(res)
                info['file'] = file
                info['type'] = type.rstrip('s')
                test = Test.find_one({
                        'name': info['name'],
                        'file': info['file'],
                        })
                if test:
                    test['tries'] = test.get('tries', 1) + 1
                else:
                    test = {
                        'created': datetime.utcnow(),
                        'tries': 1,
                        }
                test.update(info)
                id = Test.save(test, safe=True)
                ids.append(id)
                tests_info[type] += 1

        tests_info['tests_run'] += results.testsRun

        Test.remove({'file': file, '_id': {'$nin': ids}}, safe=True)

    tests_info['finished'] = datetime.utcnow()
    TestInfo.update({}, tests_info, upsert=True, safe=True)