My conftest
from unittest import mock
import aioboto3
import pytest
import pytest_asyncio
from moto import mock_aws
@pytest_asyncio.fixture
@mock_aws
async def s3_setup():
async with aioboto3.Session().client('s3', region_name='ap-east-1') as s3_client:
test_bucket = 'bucket'
test_file_name = 'key'
test_body = '0123456789'
await s3_client.create_bucket(
Bucket=test_bucket,
CreateBucketConfiguration={'LocationConstraint': 'ap-east-1'}
)
await s3_client.put_object(
Bucket=test_bucket,
Key=test_file_name,
Body=test_body
)
yield s3_client, test_bucket, test_file_name, test_body
and my simple test function
'''tests range byte calculator function'''
from typing import Tuple
from mypy_boto3_s3 import S3Client
from s3_md5.src.s3_file import S3FileHelper
async def test_calculate_range_bytes_from_part_number(s3_setup: Tuple[S3Client, str, str, str]):
'''test function'''
s3_client, test_bucket, test_file_name, _ = s3_setup
s3_file = S3FileHelper(s3_client, test_bucket, test_file_name)
await s3_file.get_file_size()
part_number = 1
chunk_size = 1000000
file_chunk_count = 10
byte_range = s3_file.calculate_range_bytes_from_part_number(
part_number, chunk_size, file_chunk_count)
assert byte_range == 'bytes=1000000-1999999'
I’ve read that moto3 and aioboto3 might not work. But I am trying to understand what I can do to make it work for my simple setup.
If I keep @pytest_asyncio.fixture
as the first decorator, I get
TypeError: cannot unpack non-iterable async_generator object
and if I swap them around, I get
botocore.exceptions.ClientError: An error occurred (InvalidAccessKeyId) when calling the CreateBucket operation: The AWS Access Key Id you provided does not exist in our records.
I get that the first error is probably the correct error given it can create the bucket but I can’t unpack the generator. Any ideas on how to approach this?