I wonder why mock_s3
decorator doesn't work when used as a decorator for pytest fixture. test_with_fixture
fails while it provides the same code as the test_without
fixture. Well, "the same" as it is decorated explicitly.
test_with_fixture
raises AccessDenied
error, but the type of S3 error it not relevant in this case. The problem is that, client.list_objects is not mocked in the test which uses fixture.
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)