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.

Install

Install pytest-moto-fixtures package from PyPI:

pip install pytest-moto-fixtures[pytest]

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.services.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.1a3.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_moto_fixtures-0.0.1a3-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_moto_fixtures-0.0.1a3.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pytest_moto_fixtures-0.0.1a3.tar.gz
Algorithm Hash digest
SHA256 03ff16b5ead210203416a7ad2e2cac0ce06f1e86ef155e6dcbd319d6906fa966
MD5 a29409c01b9d9ee00cafb495724d3362
BLAKE2b-256 8c6f8bcdd650bd03f964041fbe8bb6bb11acea3f3100c29860368dc7541891e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_moto_fixtures-0.0.1a3.tar.gz:

Publisher: release.yml on eduardoklosowski/pytest-moto-fixtures

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pytest_moto_fixtures-0.0.1a3-py3-none-any.whl
Algorithm Hash digest
SHA256 abe130919547d17ab466532e063af6ad5847c43819fd182e8a0f7ca1a666a98d
MD5 8c79ed61252f7ae18e28024d2cb7afb2
BLAKE2b-256 434cc0050111333489b79e9d6b6e14f74cfd451c43bf38c87c8b933ac9aab0de

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_moto_fixtures-0.0.1a3-py3-none-any.whl:

Publisher: release.yml on eduardoklosowski/pytest-moto-fixtures

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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