summaryrefslogtreecommitdiffstats
path: root/tests/unit/db/sqlalchemy
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2013-02-04 16:24:10 +0000
committerMark McLoughlin <markmc@redhat.com>2013-02-07 15:25:29 -0500
commit131075abb9691c204ef74bd108123d5e5fa9b9b7 (patch)
treebd0f051302ab6a4be594776371d863c9319cae10 /tests/unit/db/sqlalchemy
parentf895ca35ee029bc730b06657f3a6451086a19c58 (diff)
downloadoslo-131075abb9691c204ef74bd108123d5e5fa9b9b7.tar.gz
oslo-131075abb9691c204ef74bd108123d5e5fa9b9b7.tar.xz
oslo-131075abb9691c204ef74bd108123d5e5fa9b9b7.zip
Use importutils.try_import() for MySQLdb
This is a common pattern we've adopted elsewhere, so use it here too. Change-Id: I2e0947b4857005b478e796e9c9a7c05ea1f0d926
Diffstat (limited to 'tests/unit/db/sqlalchemy')
-rw-r--r--tests/unit/db/sqlalchemy/test_sqlalchemy.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/tests/unit/db/sqlalchemy/test_sqlalchemy.py b/tests/unit/db/sqlalchemy/test_sqlalchemy.py
index e509036..c063f0d 100644
--- a/tests/unit/db/sqlalchemy/test_sqlalchemy.py
+++ b/tests/unit/db/sqlalchemy/test_sqlalchemy.py
@@ -17,11 +17,6 @@
"""Unit tests for SQLAlchemy specific code."""
from eventlet import db_pool
-try:
- import MySQLdb
- HAS_MYSQLDB = True
-except ImportError:
- HAS_MYSQLDB = False
from sqlalchemy import Column, MetaData, Table, UniqueConstraint
from sqlalchemy.ext.declarative import declarative_base
@@ -29,8 +24,11 @@ from sqlalchemy import DateTime, Integer
from openstack.common.db.sqlalchemy import models
from openstack.common.db.sqlalchemy import session
+from openstack.common import importutils
from tests import utils as test_utils
+MySQLdb = importutils.try_import('MySQLdb')
+
class TestException(Exception):
pass
@@ -39,7 +37,7 @@ class TestException(Exception):
class DbPoolTestCase(test_utils.BaseTestCase):
def setUp(self):
super(DbPoolTestCase, self).setUp()
- if not HAS_MYSQLDB:
+ if MySQLdb is None:
self.skipTest("Required module MySQLdb missing.")
self.config(sql_dbpool_enable=True)
self.user_id = 'fake'