Best Python code snippet using autotest_python
test_importer.py
Source:test_importer.py  
...71        return 172    if len(argv) == 1:73        update_all(options.autotest_dir, options.add_noncompliant,74                   options.add_experimental, options.verbose)75        db_clean_broken(options.autotest_dir, options.verbose)76        return 077    if options.add_all:78        update_all(options.autotest_dir, options.add_noncompliant,79                   options.add_experimental, options.verbose)80    if options.clear_tests:81        db_clean_broken(options.autotest_dir, options.verbose)82    if options.tests_dir:83        options.tests_dir = os.path.abspath(options.tests_dir)84        tests = get_tests_from_fs(options.tests_dir, options.control_pattern,85                                  add_noncompliant=options.add_noncompliant)86        update_tests_in_db(tests, add_experimental=options.add_experimental,87                           add_noncompliant=options.add_noncompliant,88                           autotest_dir=options.autotest_dir,89                           verbose=options.verbose)90    if options.profile_dir:91        profilers = get_tests_from_fs(options.profile_dir, '.*py$')92        update_profilers_in_db(profilers, verbose=options.verbose,93                               add_noncompliant=options.add_noncompliant,94                               description='NA')95def update_all(autotest_dir, add_noncompliant, add_experimental, verbose):96    """Function to scan through all tests and add them to the database."""97    for path in [ 'server/tests', 'server/site_tests', 'client/tests',98                  'client/site_tests']:99        test_path = os.path.join(autotest_dir, path)100        if not os.path.exists(test_path):101            continue102        if verbose:103            print "Scanning " + test_path104        tests = []105        tests = get_tests_from_fs(test_path, "^control.*",106                                 add_noncompliant=add_noncompliant)107        update_tests_in_db(tests, add_experimental=add_experimental,108                           add_noncompliant=add_noncompliant,109                           autotest_dir=autotest_dir,110                           verbose=verbose)111    test_suite_path = os.path.join(autotest_dir, 'test_suites')112    if os.path.exists(test_suite_path):113        if verbose:114            print "Scanning " + test_suite_path115        tests = get_tests_from_fs(test_suite_path, '.*',116                                 add_noncompliant=add_noncompliant)117        update_tests_in_db(tests, add_experimental=add_experimental,118                           add_noncompliant=add_noncompliant,119                           autotest_dir=autotest_dir,120                           verbose=verbose)121    sample_path = os.path.join(autotest_dir, 'server/samples')122    if os.path.exists(sample_path):123        if verbose:124            print "Scanning " + sample_path125        tests = get_tests_from_fs(sample_path, '.*srv$',126                                 add_noncompliant=add_noncompliant)127        update_tests_in_db(tests, add_experimental=add_experimental,128                           add_noncompliant=add_noncompliant,129                           autotest_dir=autotest_dir,130                           verbose=verbose)131     132    profilers_path = os.path.join(autotest_dir, "client/profilers")133    if os.path.exists(profilers_path):134        if verbose:135            print "Scanning " + profilers_path136        profilers = get_tests_from_fs(profilers_path, '.*py$')137        update_profilers_in_db(profilers, verbose=verbose,138                               add_noncompliant=add_noncompliant,139                               description='NA')140    # Clean bad db entries141    db_clean_broken(autotest_dir, verbose)142 143def db_clean_broken(autotest_dir, verbose):144    """Remove tests from autotest_web that do not have valid control files145       Arguments:146        tests: a list of control file relative paths used as keys for deletion.147    """148    connection=db_connect()149    cursor = connection.cursor()150    # Get tests151    sql = "SELECT id, path FROM autotests";152    cursor.execute(sql)153    results = cursor.fetchall()154    for test_id, path in results:155        full_path = os.path.join(autotest_dir, path)156        if not os.path.isfile(full_path):157            if verbose:...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
