測(cè)試文件需要test_作為前綴尚猿,比如 test_storages.py
進(jìn)行tox測(cè)試:
- 進(jìn)入虛擬環(huán)境
[ubuntu@localhost cinder]$ . .tox/py27/bin/activate
- 使用指令運(yùn)行測(cè)試程序
(py27) [ubuntu@localhost cinder]$ ostestr cinder.tests.unit.storages.db.test_storages.StorageTestCase.test_storage_destroy_not_found_storage
- ostestr 不可進(jìn)行pdb調(diào)試
(py27) [ubuntu@localhost cinder]$ python -m testtools.run test_storages.StorageTestCase.test_storage_create_not_found_device
- python -m testtools.run 可以進(jìn)行pdb調(diào)試
- 退出虛擬環(huán)境
(py27) [ubuntu@localhost cinder]$ deactivate
cinder測(cè)試源碼test.py里定義了默認(rèn)數(shù)據(jù)庫(kù)連接sqlite,我們要修成mysql更適合我們的測(cè)試:
cinder\test.py:
def setUp(self):
# 配置內(nèi)存數(shù)據(jù)庫(kù)定庵,此段注釋掉,不然會(huì)連接sqlite作為數(shù)據(jù)庫(kù)
# CONF.set_default('connection', 'sqlite://', 'database')
# CONF.set_default('sqlite_synchronous', False, 'database')
# global _DB_CACHE
# if not _DB_CACHE:
# _DB_CACHE = Database(sqla_api, migration,
# sql_connection=CONF.database.connection)
# self.useFixture(_DB_CACHE)
# 配置mysql連接
CONF.set_default('connection', 'mysql+pymysql://root:secret@127.0.0.1/cinder?charset=utf8', 'database')