Skip to content

hanzhichao/pytest-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pytest-data-file

Pytest操作MySQL


如何使用

  1. 安装 pytest-db

使用pip从github安装

pip install git+https://github.com/hanzhichao/pytest-db
  1. 使用方法 在环境变量中添加
export DB_URI=mysql://root:password@localhost:3306/test

或在pytest.ini中配置

[pytest]
db_uri=mysql://root:password@localhost:3306/test

或命令行传入

$ pytest --db-uri=mysql://root:password@localhost:3306/test
  1. 使用fixture函数: db
def test_a(db):
    print(db.query('select id from user limit 1;')

使用pytest -s 运行,查看结果

...
[{'id': 123321336}]
...

游标使用pymysql.cursors.DictCursor,结果使用fetchall,返回列表嵌套字典格式的结果

  1. db对象支持的方法
  • db.query(sql): 执行查询sql
  • db.change_db(sql): 执行修改sql

About

Pytest plugin for mysql query or change

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages