tox测试 笔记

测试文件需要test_作为前缀,比如 test_storages.py

进行tox测试:

  1. 进入虚拟环境
[ubuntu@localhost cinder]$ . .tox/py27/bin/activate

  1. 使用指令运行测试程序
(py27) [ubuntu@localhost cinder]$ ostestr cinder.tests.unit.storages.db.test_storages.StorageTestCase.test_storage_destroy_not_found_storage
  • ostestr 不可进行pdb调试
(py27) [ubuntu@localhost cinder]$ python -m testtools.run test_storages.StorageTestCase.test_storage_create_not_found_device
  • python -m testtools.run 可以进行pdb调试
  1. 退出虚拟环境
(py27) [ubuntu@localhost cinder]$ deactivate

cinder测试源码test.py里定义了默认数据库连接sqlite,我们要修成mysql更适合我们的测试:

cinder\test.py:

def setUp(self):

        # 配置内存数据库,此段注释掉,不然会连接sqlite作为数据库
        # 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')

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容