Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to start more than just S3 ? #16

Open
kornicameister opened this issue Feb 27, 2025 · 2 comments
Open

How to start more than just S3 ? #16

kornicameister opened this issue Feb 27, 2025 · 2 comments

Comments

@kornicameister
Copy link

Can we make a fixture that can be overridden that starts more than just S3?

@phillipuniverse
Copy link
Owner

@kornicameister good suggestion, there's not a great way to do that at the moment.

I'm thinking allow users to specify an optional fixture that I can then read from here:

services_to_start = ("s3",)
"""
1. Add a new entry to the 'extras' section in pyproject.toml for types-aiobotocore, moto and boto3-stubs like 'dynamodb' or 'ec2'
2. Add to this tuple the service that you want to mock, the same as the extra you added
"""

In other words, make it to where the services_to_start is injectable/overridable.

I'll probably need some additional refactoring on the extra S3 resources started here too:

@pytest.fixture
async def aioboto3_s3_client(moto_patch_session: None) -> AsyncIterator[S3Client]:
region = "us-east-1"
session = aioboto3.Session(region_name=region)
async with session.client("s3", region_name=region) as client: # type: S3Client
yield client
@pytest.fixture
async def aioboto3_s3_resource(moto_patch_session: None) -> AsyncIterator[S3ServiceResource]:
region = "us-east-1"
session = aioboto3.Session(region_name=region)
async with session.resource("s3", region_name=region) as resource: # type: S3ServiceResource
yield resource

Maybe I'll just drop these altogether, they aren't all that useful. The most important part is the mocked Session.

Does that sound about like what you'd expect? Any other way you'd like to be able to specify which services to start?

@kornicameister
Copy link
Author

Another idea I had was to make it a configuration that happens via pyproject.toml for instance but more specifically via pytest's configuration options.

But honestly speaking yeah they might not be needed if all we need to create a new client/resource is using moto_patch_session fixture. Alternatively you may just wanna expose the the fixture for session itself and make it use bucket_name fixture that, if defined, in project's conftest.py will override the one you have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants