我想知道为什么mock_s3decorator在用作pytest fixture的装饰器时不起作用.test_with_fixture在提供与test_without灯具相同的代码时失败.嗯,"相同",因为它明确地装饰.
test_with_fixture引发AccessDenied错误,但S3错误的类型在这种情况下不相关.问题是,在使用fixture的测试中不会模拟client.list_objects.
pytest - 3.1.2
moto - 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)
Run Code Online (Sandbox Code Playgroud)