Fixtures for testing code that interacts with AWS
Project description
pytest-moto-fixtures
pytest fixtures for testing code that integrates with AWS using moto as a mock.
Examples of Use
Code for test:
class Example:
def __init__(self, sqs_client, queue_url):
self._sqs_client = sqs_client
self._queue_url = queue_url
def run(self, values):
total = 0
for value in values:
total += value
self._sqs_client.send_message(QueueUrl=self._queue_url, MessageBody=f'Value processed: {value}')
return total
Test example using fixture:
from random import randint
def test_example_with_fixture(sqs_queue):
values = [randint(1, 10) for _ in range(randint(3, 10))]
expected = sum(values)
sut = Example(sqs_client=sqs_queue.client, queue_url=sqs_queue.url)
returned = sut.run(values)
assert returned == expected
assert len(sqs_queue) == len(values)
for value, message in zip(values, sqs_queue):
assert message['Body'] == f'Value processed: {value}'
Test example using context:
from random import randint
from pytest_moto_fixtures.clients.sqs import sqs_create_queue
def test_example_with_context(sqs_client):
values = [randint(1, 10) for _ in range(randint(3, 10))]
expected = sum(values)
with sqs_create_queue(sqs_client=sqs_client, name='my-queue') as sqs_queue:
sut = Example(sqs_client=sqs_client, queue_url=sqs_queue.url)
returned = sut.run(values)
assert returned == expected
assert len(sqs_queue) == len(values)
for value, message in zip(values, sqs_queue):
assert message['Body'] == f'Value processed: {value}'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest_moto_fixtures-0.0.1a1.tar.gz
.
File metadata
- Download URL: pytest_moto_fixtures-0.0.1a1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e4422086de7d16c4c5fb920c2f1a72a5dfe87b2d687af3bd6a50dc9caff1dae |
|
MD5 | 57a7dca2d3601d0cc8793b2a91c31b1f |
|
BLAKE2b-256 | ff62b3ba7d77c89eda76dc644db53a7eadb3772bcba31b12463b64019b737a74 |
File details
Details for the file pytest_moto_fixtures-0.0.1a1-py3-none-any.whl
.
File metadata
- Download URL: pytest_moto_fixtures-0.0.1a1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a6896b14fc8250cc0a4a83d92a42ed2d22b3a3f01247a613352dd63089d1702 |
|
MD5 | e5eef69f87df897d7817c57677adecec |
|
BLAKE2b-256 | f279c955d19213e0dc004598ab06087238df7ea0959e5f712e8d31c4ddaad88f |