How to use destroy_test_database method in autotest

Best Python code snippet using autotest_python

setup_test_environment.py

Source:setup_test_environment.py Github

copy

Full Screen

...12from django.db import connection13from autotest_lib.frontend.afe import readonly_connection14def set_test_database(database):15 settings.DATABASE_NAME = database16 destroy_test_database()17def backup_test_database():18 temp_fd, backup_path = tempfile.mkstemp(suffix='.test_db_backup')19 os.close(temp_fd)20 shutil.copyfile(settings.DATABASE_NAME, backup_path)21 return backup_path22def restore_test_database(backup_path):23 connection.close()24 shutil.copyfile(backup_path, settings.DATABASE_NAME)25def cleanup_database_backup(backup_path):26 os.remove(backup_path)27def run_syncdb(verbosity=0):28 management.syncdb(verbosity, interactive=False)29def destroy_test_database():30 connection.close()31 # Django brilliantly ignores close() requests on in-memory DBs to keep us32 # naive users from accidentally destroying data. So reach in and close33 # the real connection ourselves.34 # Note this depends on Django internals and will likely need to be changed35 # when we move to Django 1.x.36 real_connection = connection.connection37 if real_connection is not None:38 real_connection.close()39 connection.connection = None40def set_up():41 run_syncdb()42 readonly_connection.ReadOnlyConnection.set_globally_disabled(True)43def tear_down():44 readonly_connection.ReadOnlyConnection.set_globally_disabled(False)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful