diff --git a/py_dbcn/connectors/core/database.py b/py_dbcn/connectors/core/database.py index e2e913313e148547765777a3446a62dd7ccfd02b..53fdf0ec3b619f3f96811505687b4ab64d36ed06 100644 --- a/py_dbcn/connectors/core/database.py +++ b/py_dbcn/connectors/core/database.py @@ -133,7 +133,7 @@ class BaseDatabase: # Check if provided database matches value in list. if db_name in available_databases: # Database already exists. Raise error. - raise ValueError( + raise self._base.errors.database_already_exists( 'Could not find database "{0}". Valid options are {1}.'.format(db_name, available_databases) ) @@ -160,7 +160,7 @@ class BaseDatabase: # Check if provided database matches value in list. if db_name not in available_databases: # Database does not exist. Raise error. - raise ValueError('Database with name "{0}" does not exist.'.format(db_name)) + raise self._base.errors.database_does_not_exist('Database with name "{0}" does not exist.'.format(db_name)) # Remove database. query = 'DROP DATABASE {0};'.format(db_name) diff --git a/py_dbcn/connectors/postgresql/database.py b/py_dbcn/connectors/postgresql/database.py index 64ee6f2a9836055009d4aeab8312b140eff359a8..5ce18a888e3bf1392a3638f31dd1218fbf5cf2a1 100644 --- a/py_dbcn/connectors/postgresql/database.py +++ b/py_dbcn/connectors/postgresql/database.py @@ -98,7 +98,7 @@ class PostgresqlDatabase(BaseDatabase): break if not db_found: # Database does not exist. Raise error. - raise ValueError( + raise self._base.errors.database_does_not_exist( 'Could not find database "{0}". Valid options are {1}.'.format(db_name, available_databases) ) diff --git a/tests/connectors/core/test_database.py b/tests/connectors/core/test_database.py index f935d6c5e0945522ba89dc543c31fd9a457018e6..df28a1abeaf412ba32f1ec28c6c35544a99ae447 100644 --- a/tests/connectors/core/test_database.py +++ b/tests/connectors/core/test_database.py @@ -53,13 +53,17 @@ class CoreDatabaseTestMixin: with self.subTest('With select_1 database selected'): db_name = '{0}__select_1'.format(self.test_db_name) - # Verify database exists. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. try: - self.connector.database.create(db_name) - except self.connector.errors.database_already_exists: + self.connector.database.drop(db_name, display_query=False, display_results=False) + except self.connector.errors.database_does_not_exist: # Database already exists, as we want. pass + # Create desired database. + self.connector.database.create(db_name) + # Switch databases and verify select changed. self.connector.database.use(db_name) result = self.connector.database.select() @@ -72,13 +76,17 @@ class CoreDatabaseTestMixin: with self.subTest('With select_2 database selected'): db_name = '{0}__select_2'.format(self.test_db_name) - # Verify database exists. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. try: - self.connector.database.create(db_name) - except self.connector.errors.database_already_exists: + self.connector.database.drop(db_name, display_query=False, display_results=False) + except self.connector.errors.database_does_not_exist: # Database already exists, as we want. pass + # Create desired database. + self.connector.database.create(db_name) + # Switch databases and verify select changed. self.connector.database.use(db_name) result = self.connector.database.select() @@ -95,13 +103,17 @@ class CoreDatabaseTestMixin: db_name = '{0}__show'.format(self.test_db_name) with self.subTest('SHOW query when database exists'): - # Verify database exists. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. try: - self.connector.database.create(db_name) - except self.connector.errors.database_already_exists: + self.connector.database.drop(db_name, display_query=False, display_results=False) + except self.connector.errors.database_does_not_exist: # Database already exists, as we want. pass + # Create desired database. + self.connector.database.create(db_name) + # Run test query. results = self.connector.database.show() @@ -132,18 +144,19 @@ class CoreDatabaseTestMixin: """ db_name = '{0}__create__success'.format(self.test_db_name) - # Verify database does not yet exist. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. try: - self.connector.database.drop(db_name) - except ValueError: - # Database does not yet exist, as we want. + self.connector.database.drop(db_name, display_query=False, display_results=False) + except self.connector.errors.database_does_not_exist: + # Database already exists, as we want. pass # Check databases prior to test query. Verify expected database did not return. results = self.connector.database.show() self.assertNotIn(db_name.casefold(), (str(x).casefold() for x in results)) - # Run test query. + # Create desired database. self.connector.database.create(db_name) # Check databases after test query. Verify expected database returned. @@ -157,13 +170,17 @@ class CoreDatabaseTestMixin: """ db_name = '{0}__create__failure'.format(self.test_db_name) - # Verify database does not yet exist. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. try: - self.connector.database.create(db_name) - except self.connector.errors.database_already_exists: + self.connector.database.drop(db_name, display_query=False, display_results=False) + except self.connector.errors.database_does_not_exist: # Database already exists, as we want. pass + # Create desired database. + self.connector.database.create(db_name) + # Check databases prior to test query. Verify expected database returned. results = self.connector.database.show() self.assertGreaterEqual(len(results), 1) @@ -184,13 +201,17 @@ class CoreDatabaseTestMixin: """ db_name = '{0}__use__success'.format(self.test_db_name) - # Verify database exists. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. try: - self.connector.database.create(db_name) - except self.connector.errors.database_already_exists: + self.connector.database.drop(db_name, display_query=False, display_results=False) + except self.connector.errors.database_does_not_exist: # Database already exists, as we want. pass + # Create desired database. + self.connector.database.create(db_name) + # Check databases prior to test query. Verify expected database returned. results = self.connector.database.show() self.assertGreaterEqual(len(results), 1) @@ -212,11 +233,12 @@ class CoreDatabaseTestMixin: """ db_name = '{0}__use__failure'.format(self.test_db_name) - # Verify database does not yet exist. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. try: - self.connector.database.drop(db_name) - except ValueError: - # Database does not exist, as we want. + self.connector.database.drop(db_name, display_query=False, display_results=False) + except self.connector.errors.database_does_not_exist: + # Database already exists, as we want. pass # Check databases prior to test query. Verify expected database did not return. @@ -233,13 +255,17 @@ class CoreDatabaseTestMixin: """ db_name = '{0}__delete__success'.format(self.test_db_name) - # Verify database does not yet exist. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. try: - self.connector.database.create(db_name) - except self.connector.errors.database_already_exists: + self.connector.database.drop(db_name, display_query=False, display_results=False) + except self.connector.errors.database_does_not_exist: # Database already exists, as we want. pass + # Create desired database. + self.connector.database.create(db_name) + # Check databases prior to test query. Verify expected database returned. results = self.connector.database.show() self.assertGreaterEqual(len(results), 1) @@ -259,10 +285,11 @@ class CoreDatabaseTestMixin: """ db_name = '{0}__delete__failure'.format(self.test_db_name) - # Verify database does not yet exist. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. try: - self.connector.database.drop(db_name) - except ValueError: + self.connector.database.drop(db_name, display_query=False, display_results=False,) + except self.connector.errors.database_does_not_exist: # Database does not yet exist, as we want. pass @@ -271,5 +298,5 @@ class CoreDatabaseTestMixin: self.assertNotIn(db_name, results) # Run test query. - with self.assertRaises(ValueError): + with self.assertRaises(self.connector.errors.database_does_not_exist): self.connector.database.delete(db_name) diff --git a/tests/connectors/core/test_display.py b/tests/connectors/core/test_display.py index 32005a54bdf05719a694aa3c2b8da66aed1c997c..29184bb31631aafd68e24dabb97705582cd143aa 100644 --- a/tests/connectors/core/test_display.py +++ b/tests/connectors/core/test_display.py @@ -196,7 +196,19 @@ class CoreDisplayTablesTestMixin: # Since this directly tests display of tables, ensure we use a fresh database. db_name = '{0}d__tables__show'.format(self.test_db_name[0:-15]) - self.connector.database.create(db_name, display_query=False) + + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + self.connector.database.drop(db_name, display_query=False, display_results=False) + except self.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. + self.connector.database.create(db_name) + + # Select desired database. self.connector.database.use(db_name, display_query=False) with self.subTest('With no tables present'): @@ -315,7 +327,19 @@ class CoreDisplayTablesTestMixin: # Since this directly tests display of tables, ensure we use a fresh database. db_name = '{0}d__tables__desc'.format(self.test_db_name[0:-15]) - self.connector.database.create(db_name, display_query=False) + + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + self.connector.database.drop(db_name, display_query=False, display_results=False) + except self.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. + self.connector.database.create(db_name) + + # Select desired database. self.connector.database.use(db_name, display_query=False) # Create initial table to describe. diff --git a/tests/connectors/mysql/test_database.py b/tests/connectors/mysql/test_database.py index f2c353f24a59c24e77a80b9d452bcfe9a1d04b00..ce4ec986f99b97df2fd8d5804f17274dfa1a9cf1 100644 --- a/tests/connectors/mysql/test_database.py +++ b/tests/connectors/mysql/test_database.py @@ -24,8 +24,18 @@ class TestMysqlDatabase(TestMysqlDatabaseParent, CoreDatabaseTestMixin): # Define database name to use in tests. cls.test_db_name = '{0}test_database'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. diff --git a/tests/connectors/mysql/test_display.py b/tests/connectors/mysql/test_display.py index 05f2403a503073756c060afb3a24519494cf7c10..26d3b1e25b21305bd8edbfd938d9e52885de924c 100644 --- a/tests/connectors/mysql/test_display.py +++ b/tests/connectors/mysql/test_display.py @@ -38,8 +38,18 @@ class TestMysqlDisplayCore(TestMysqlDatabaseParent, CoreDisplayBaseTestMixin): # Define database name to use in tests. cls.test_db_name = '{0}test_display__core'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. @@ -70,8 +80,18 @@ class TestMysqlDisplayTables(TestMysqlDatabaseParent, CoreDisplayTablesTestMixin # Define database name to use in tests. cls.test_db_name = '{0}test_display__tables'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. @@ -105,8 +125,18 @@ class TestMysqlDisplayRecords(TestMysqlDatabaseParent, CoreDisplayRecordsMixin): # Define database name to use in tests. cls.test_db_name = '{0}test_display__records'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. diff --git a/tests/connectors/mysql/test_query.py b/tests/connectors/mysql/test_query.py index 0454b684a83e6b2e92bd27863ac1fe3f90e7b961..e97e790826e6f1ebde966b6baf048e7475223e31 100644 --- a/tests/connectors/mysql/test_query.py +++ b/tests/connectors/mysql/test_query.py @@ -24,8 +24,18 @@ class TestMysqlQuery(TestMysqlDatabaseParent, CoreQueryTestMixin): # Define database name to use in tests. cls.test_db_name = '{0}test_query'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. diff --git a/tests/connectors/mysql/test_records.py b/tests/connectors/mysql/test_records.py index d617c2f18202b236e3d049182a90666506065944..5c682864067d0d131faf9fea01f347b772cb120c 100644 --- a/tests/connectors/mysql/test_records.py +++ b/tests/connectors/mysql/test_records.py @@ -26,8 +26,18 @@ class TestMysqlRecords(TestMysqlDatabaseParent, CoreRecordsTestMixin): # Define database name to use in tests. cls.test_db_name = '{0}test_records'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. diff --git a/tests/connectors/mysql/test_tables.py b/tests/connectors/mysql/test_tables.py index 7012fb0b2c6d718e1f3c0875d78aaa379fca6618..cfa91a5026d1d779c329e257c37ddf7716ccf63b 100644 --- a/tests/connectors/mysql/test_tables.py +++ b/tests/connectors/mysql/test_tables.py @@ -29,8 +29,18 @@ class TestMysqlTables(TestMysqlDatabaseParent, CoreTablesTestMixin): # Define database name to use in tests. cls.test_db_name = '{0}test_tables'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. diff --git a/tests/connectors/mysql/test_utils.py b/tests/connectors/mysql/test_utils.py index 35c78e86ad97ea53bfe0086e7f0dffc48633e056..7597ab157995b3842b563917cb5ab5c97725da48 100644 --- a/tests/connectors/mysql/test_utils.py +++ b/tests/connectors/mysql/test_utils.py @@ -25,8 +25,18 @@ class TestMysqlUtils(TestMysqlDatabaseParent, CoreUtilsTestMixin): # Define database name to use in tests. cls.test_db_name = '{0}test_utils'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. diff --git a/tests/connectors/mysql/test_validate.py b/tests/connectors/mysql/test_validate.py index f32fd49a542e8e932146c0a7b0b7ab19d38fc4bd..cec092f02200bd08a1a99955a1b06b2bfaea8f41 100644 --- a/tests/connectors/mysql/test_validate.py +++ b/tests/connectors/mysql/test_validate.py @@ -24,8 +24,18 @@ class TestMysqlValidate(TestMysqlDatabaseParent, CoreValidateTestMixin): # Define database name to use in tests. cls.test_db_name = '{0}test_validate'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. diff --git a/tests/connectors/postgresql/test_database.py b/tests/connectors/postgresql/test_database.py index c59a5db6d6a6862fa9af0556f8f95e6b17cc18fc..c255d95b277646417f6f58678bd5d45fe4870402 100644 --- a/tests/connectors/postgresql/test_database.py +++ b/tests/connectors/postgresql/test_database.py @@ -24,8 +24,18 @@ class TestPostgresqlDatabase(TestPostgresqlDatabaseParent, CoreDatabaseTestMixin # Define database name to use in tests. cls.test_db_name = '{0}test_database'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. diff --git a/tests/connectors/postgresql/test_display.py b/tests/connectors/postgresql/test_display.py index 32d87c32ce8bd38e179f5d30085ed6b0587ebf0c..10936accae80914b37506267c52060680ae04dba 100644 --- a/tests/connectors/postgresql/test_display.py +++ b/tests/connectors/postgresql/test_display.py @@ -36,8 +36,18 @@ class TestPostgresqlDisplay(TestPostgresqlDatabaseParent, CoreDisplayBaseTestMix # Define database name to use in tests. cls.test_db_name = '{0}test_display__core'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. @@ -68,8 +78,18 @@ class TestPostgresqlDisplayTables(TestPostgresqlDatabaseParent, CoreDisplayTable # Define database name to use in tests. cls.test_db_name = '{0}test_display__tables'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. @@ -103,8 +123,18 @@ class TestPostgreSQLDisplayRecords(TestPostgresqlDatabaseParent, CoreDisplayReco # Define database name to use in tests. cls.test_db_name = '{0}test_display__records'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. diff --git a/tests/connectors/postgresql/test_query.py b/tests/connectors/postgresql/test_query.py index db51b24828b7505069d8709f7c7aec1d128383ea..18a8ed139d992627a80b371edbd98986ebce5bdc 100644 --- a/tests/connectors/postgresql/test_query.py +++ b/tests/connectors/postgresql/test_query.py @@ -24,8 +24,18 @@ class TestPostgresqlQuery(TestPostgresqlDatabaseParent, CoreQueryTestMixin): # Define database name to use in tests. cls.test_db_name = '{0}test_query'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. diff --git a/tests/connectors/postgresql/test_records.py b/tests/connectors/postgresql/test_records.py index 0027928ec3ba03914ea8f859e4a5b11d262779eb..4acf2436bc7184d15c423097b3a1fd6729da0ab0 100644 --- a/tests/connectors/postgresql/test_records.py +++ b/tests/connectors/postgresql/test_records.py @@ -26,8 +26,18 @@ class TestPostgresqlRecords(TestPostgresqlDatabaseParent, CoreRecordsTestMixin): # Define database name to use in tests. cls.test_db_name = '{0}test_records'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. diff --git a/tests/connectors/postgresql/test_tables.py b/tests/connectors/postgresql/test_tables.py index b199fdf1165f885ce9955c9cd34054c00bff92e2..c9120121236071e8913b5fececc218b9f2b00c0d 100644 --- a/tests/connectors/postgresql/test_tables.py +++ b/tests/connectors/postgresql/test_tables.py @@ -25,8 +25,18 @@ class TestPostgresqlTables(TestPostgresqlDatabaseParent, CoreTablesTestMixin): # Define database name to use in tests. cls.test_db_name = '{0}test_tables'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables. diff --git a/tests/connectors/postgresql/test_validate.py b/tests/connectors/postgresql/test_validate.py index f551bdb0ebc54cfcaf0d8e4a8ed22da7c5c5360d..24e56592490a391f00aefa55412037d9699ea26d 100644 --- a/tests/connectors/postgresql/test_validate.py +++ b/tests/connectors/postgresql/test_validate.py @@ -24,8 +24,18 @@ class TestPostgresqlValidate(TestPostgresqlDatabaseParent, CoreValidateTestMixin # Define database name to use in tests. cls.test_db_name = '{0}test_validate'.format(cls.test_db_name_start) - # Initialize database for tests. + # Ensure database does not currently exists. + # Guarantees tests are done from a consistent state. + try: + cls.connector.database.drop(cls.test_db_name, display_query=False, display_results=False) + except cls.connector.errors.database_does_not_exist: + # Database already exists, as we want. + pass + + # Create desired database. cls.connector.database.create(cls.test_db_name) + + # Select desired database. cls.connector.database.use(cls.test_db_name) # Check that database has no tables.