pytest用dynamodb夹具
pytest-dynamodb的Python项目详细描述
这是什么?
这是一个pytest插件,它使您能够测试依赖于正在运行的dynamodb数据库的代码。 它允许您为dynamodb进程和客户机(aws boto术语中的资源)指定fixture。
如何使用
插件包含两个装置
- dynamodb-它是一个具有功能范围的客户机/资源fixture。每次测试后,它都会把表放到dynamodb中。
- dynamodb_proc-会话范围的fixture,它在dynamodb实例首次使用时启动,在测试结束时停止。
只需将其中一个fixture包含到测试fixture列表中。
如果需要,您还可以创建额外的dynamodb客户机和处理装置:
frompytest_dynamodbimportfactoriesdynamodb_my_proc=factories.dynamodb_proc(port=None,logsdir='/tmp',delay=True)dynamodb_my=factories.dynamodb('dynamodb_my_proc')
注意
每个dynamodb进程fixture都可以通过fixture工厂参数以不同的方式配置。
配置
可以通过三种方式定义设置,即fixture factory参数、命令行选项和pytest.ini配置选项。 您可以选择您喜欢的设置,但请记住,这些设置的处理顺序如下:
- ^{tt1}$
- ^{tt2}$
- ^{tt3}$
DynamoDB option | Fixture factory argument | Command line option | pytest.ini option | Default |
---|---|---|---|---|
Path to dynamodb jar file | dynamodb_dir | –dynamodb-dir | dynamodb_dir | /tmp/dynamodb |
host | host | –dynamodb-host | dynamodb_host | 127.0.0.1 |
port | port | –dynamodb-port | dynamodb_port | random |
AWS Access Key | access_key | –dynamodb-aws_access_key | dynamodb_aws_access_key | access_key |
AWS Secret Key | secret_key | –dynamodb-aws_secret_key | dynamodb_aws_secret_key | secret_key |
AWS Region | region | –dynamodb-aws_region | dynamodb_aws_region | us-west-1 |
Introduce delays | delay | –dynamodb-delay | dynamodb_delay | false |
示例用法:
在您自己的装置中将其作为参数传递
dynamodb_proc=factories.dynamodb_proc(port=8888)
运行测试时使用--dynamodb-port命令行选项
py.test tests --dynamodb-port=8888
在pytest.ini文件中将端口指定为dynamodb_port。
To do so, put a line like the following under the ^{tt7}$ section of your ^{tt6}$:
[pytest]dynamodb_port=8888
更改日志
1.2.0
[增强]配置AWS区域和凭据的能力,
Note
apparently local dynamo operates on these so whatever you’ll set when creating table, is whatever is required when accessing the table
1.1.1
- [增强]删除了path.py依赖项
1.1.0
- [增强]将不推荐的getfuncargvalaue更改为getfixturevalues,至少需要pytest 3.0.0
1.0.1
- [增强]将执行器超时设置为60。默认情况下,mirakuru会无限期等待,这可能会导致测试挂起
1.0.0
- 创建命令行和pytest.ini配置选项以引入延迟
- 为dynamodb_dir创建命令行和pytest.ini配置选项
- 为主机创建命令行和pytest.ini配置选项
- 为端口创建命令行和pytest.ini配置选项
- 从pytest dbfixtures中提取的代码