【发布时间】:2017-06-23 10:04:04
【问题描述】:
我想知道为什么 mock_s3 装饰器在用作 pytest 夹具的装饰器时不起作用。 test_with_fixture 在提供与 test_without 夹具相同的代码时失败。好吧,“相同”,因为它被明确地装饰。
test_with_fixture 引发 AccessDenied 错误,但在这种情况下与 S3 错误的类型无关。问题是,client.list_objects 在使用夹具的测试中没有被模拟。
pytest - 3.1.2
摩托 - 1.0.1
boto3 - 1.0.4
import pytest
import boto3
from moto import mock_s3
BUCKET = 'Foo'
@pytest.fixture()
@mock_s3
def moto_boto():
res = boto3.resource('s3')
res.create_bucket(Bucket=BUCKET)
def test_with_fixture(moto_boto):
client = boto3.client('s3')
client.list_objects(Bucket=BUCKET)
@mock_s3
def test_without_fixture():
res = boto3.resource('s3')
res.create_bucket(Bucket=BUCKET)
client = boto3.client('s3')
client.list_objects(Bucket=BUCKET)
【问题讨论】:
标签: python mocking pytest boto3 moto