Skip to main content

Add your description here

Project description

Test Scenarios

Test Scenarios is a small Python library that simplifies writing integration tests by providing easy-to-use scenario definitions backed by MongoDB. It makes setup and teardown of test data explicit and repeatable, so your integration tests stay reliable and easy to reason about.

Key features

  • Minimal, opinionated API for defining scenarios (collections + documents)
  • Easy pytest integration via fixtures
  • Works with local or remote MongoDB instances
  • Focused on readability and test determinism

Installation

For development:

python -m venv .venv
source .venv/bin/activate
pip install -e .
pip install -r requirements-dev.txt

If published to PyPI, you can install the package:

pip install pytest-scenarios

Or with uv:

uv add pytest-scenarios --dev

Or with Poetry:

poetry add pytest-scenarios --group dev

Configuration

Set the MongoDB connection URI via environment variable:

export MONGODB_URI="mongodb://localhost:27017"

Getting started (pytest)

A simple test:

def test_example(
    scenario_builder: ScenarioBuilder, db: Database
):
    """Test that scenario_fixture allows scenario creation"""
    inserted_ids_by_collection = scenario_builder.create(
        {
            "customers": [
                {"name": "Alice", "status": "inactive"},
                {"name": "Louis", "age": 25},
            ],
            "orders": [
                {
                    "id": "order_001",
                    "items": [
                        {"price": 19.99, "product_id": "book_123", "quantity": 1}
                    ],
                },
                {
                    "id": "order_002",
                    "items": None,
                    "tax": 0.2,
                },
            ],
        }
    )
    for collection_name, inserted_ids in inserted_ids_by_collection:
        assert len(inserted_ids) == 2

Run tests:

pytest -q

Contributing

Contributions welcome. Please add tests for new features and follow the project's coding standards.

License

MIT

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_scenarios-0.0.3.tar.gz (3.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_scenarios-0.0.3-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file pytest_scenarios-0.0.3.tar.gz.

File metadata

  • Download URL: pytest_scenarios-0.0.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_scenarios-0.0.3.tar.gz
Algorithm Hash digest
SHA256 d5dc831bc2c03eefa54ebfed84a612d6bb7a003306aae463b28a388e2597c598
MD5 3a234115a8fb8a3cf983f5b4374de5ad
BLAKE2b-256 5413a2a140c16674dcd059305be146911ea7db3b76a00a311881fc60845cd687

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_scenarios-0.0.3.tar.gz:

Publisher: release.yaml on carlosvin/pytest-scenarios

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_scenarios-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_scenarios-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 78921ae228930dde880c1f003044c06895297139c074211c50a4b876a17a41d4
MD5 396a5264d0a86b323bd7dd3772a3d6ef
BLAKE2b-256 83989228dfbb9b6cfcd2b7310e421fc4b693f04bece95e426d268ea2dc6573dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_scenarios-0.0.3-py3-none-any.whl:

Publisher: release.yaml on carlosvin/pytest-scenarios

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