Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_moto_fixtures-0.0.1a1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

pytest_moto_fixtures-0.0.1a1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest_moto_fixtures-0.0.1a1.tar.gz.

File metadata

File hashes

Hashes for pytest_moto_fixtures-0.0.1a1.tar.gz
Algorithm Hash digest
SHA256 7e4422086de7d16c4c5fb920c2f1a72a5dfe87b2d687af3bd6a50dc9caff1dae
MD5 57a7dca2d3601d0cc8793b2a91c31b1f
BLAKE2b-256 ff62b3ba7d77c89eda76dc644db53a7eadb3772bcba31b12463b64019b737a74

See more details on using hashes here.

File details

Details for the file pytest_moto_fixtures-0.0.1a1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_moto_fixtures-0.0.1a1-py3-none-any.whl
Algorithm Hash digest
SHA256 5a6896b14fc8250cc0a4a83d92a42ed2d22b3a3f01247a613352dd63089d1702
MD5 e5eef69f87df897d7817c57677adecec
BLAKE2b-256 f279c955d19213e0dc004598ab06087238df7ea0959e5f712e8d31c4ddaad88f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page