Skip to content

Instantly share code, notes, and snippets.

@bryanyang0528
Created May 15, 2020 15:29
Show Gist options
  • Save bryanyang0528/653346b6d1a90b616ec544d0dd5fe699 to your computer and use it in GitHub Desktop.
Save bryanyang0528/653346b6d1a90b616ec544d0dd5fe699 to your computer and use it in GitHub Desktop.
mysql
from unittest import TestCase
import testing.mysqld
MYSQLD_FACTORY = testing.mysqld.MysqldFactory(cache_initialized_db=True)
def tearDownModule():
"""Tear down databases after test script has run.
https://docs.python.org/3/library/unittest.html#setupclass-and-teardownclass
"""
MYSQLD_FACTORY.clear_cache()
class TestMySQLBase(TestCase):
@classmethod
def setUpClass(cls):
cls.mysql = MYSQLD_FACTORY()
cls.params = cls.mysql.dsn()
cls.db_engine = create_engine(cls.mysql.url())
cls.session = mysql.db_init(cls.db_engine)
def setUp(self) -> None:
mysql.db_init(self.db_engine)
self.client = get_mysql_client(self.params)
def tearDown(self):
mysql.db_drop(self.db_engine)
self.client.connection.close()
@classmethod
def tearDownClass(cls):
cls.mysql.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment