Skip to main content

lexigram-testing

Centralized testing infrastructure for Lexigram Framework — Fixtures, factories, and utilities.


Overview

lexigram-testing provides ready-made fake implementations for every core protocol so unit tests stay fast, isolated, and free of real infrastructure. It ships with a pytest plugin for auto-discovered fixtures, factory helpers for domain objects, and a TestContainer builder for integration-test DI.


Full documentation: docs.lexigram.dev

Install

uv add --dev lexigram-testing

# With extras for specific backends
uv add --dev "lexigram-testing[db]"    # aiosqlite, asyncpg
uv add --dev "lexigram-testing[web]"   # httpx, starlette
uv add --dev "lexigram-testing[ai]"     # lexigram-ai

Quick Start

import pytest
from lexigram.testing.fixtures import (
    fake_cache,
    fake_db,
    fake_event_bus,
    fake_task_queue,
)


class TestUserService:
    @pytest.fixture
    def cache(self) -> FakeCacheBackend:
        return FakeCacheBackend()

    @pytest.fixture
    def service(self, cache: FakeCacheBackend) -> UserService:
        return UserService(cache=cache)

    @pytest.mark.asyncio
    async def test_returns_cached_user(self, service: UserService, cache: FakeCacheBackend) -> None:
        await cache.set("user:123", {"id": "123", "name": "Alice"})
        result = await service.find_cached("123")
        assert result.is_ok()
        assert result.unwrap().name == "Alice"

Testing

from lexigram import Application
from lexigram.testing.clients.cache import FakeCacheBackend
from lexigram.testing.clients.events import FakeEventBus
from lexigram.testing.clients.tasks import FakeTaskQueue


@pytest.mark.asyncio
async def test_places_order_emits_event(self, fake_event_bus: FakeEventBus) -> None:
    service = OrderService(bus=fake_event_bus)
    await service.place(order)

    assert fake_event_bus.published_count("OrderPlaced") == 1
    event = fake_event_bus.last_published("OrderPlaced")
    assert event.order_id == order.id


@pytest.mark.asyncio
async def test_enqueues_welcome_email(self, fake_queue: FakeTaskQueue) -> None:
    service = UserService(queue=fake_queue)
    await service.register(new_user)

    assert fake_queue.enqueued_count("send_welcome_email") == 1
    job = fake_queue.last_enqueued("send_welcome_email")
    assert job.kwargs["email"] == new_user.email

Available Fakes

Class Implements Location
FakeCacheBackend CacheBackend lexigram.testing.clients.cache
FakeDatabase DatabaseProviderProtocol lexigram.testing.clients.db
FakeEventBus EventBusProtocol lexigram.testing.clients.events
FakeCommandBus CommandBusProtocol lexigram.testing.clients.events
FakeQueryBus QueryBusProtocol lexigram.testing.clients.events
FakeTaskQueue TaskQueueProtocol lexigram.testing.clients.tasks
FakeTokenManager TokenManager lexigram.testing.clients.auth
FakeSearchEngine SearchEngineProtocol lexigram.testing.clients.search
FakeAIClient LLMClientProtocol lexigram.testing.clients.ai
FakeSecretStore SecretStoreProtocol lexigram.testing.clients.auth

Key Features

  • Zero infrastructure — all fakes run in-process; no Docker or external services needed
  • Assertion helperspublished_count(), last_published(), enqueued_count(), etc.
  • Async-first — all fakes implement the same async protocols as real backends
  • pytest plugin — auto-registered fixtures and @pytest.mark.integration marker
  • Factory helpersUserFactory, OrderFactory, etc. via lexigram.testing.data
  • Container builderTestContainer.from_providers([...]) for integration-test DI
  • Reproducible — deterministic IDs and timestamps for snapshot testing

pytest Plugin

# pyproject.toml
[tool.pytest.ini_options]
asyncio_mode = "auto"
markers = [
    "integration: marks tests as integration tests (deselect by default)",
]
uv run pytest -m "not integration"   # unit tests only (fast)
uv run pytest -m integration         # integration tests

Key Source Files

File What it contains
src/lexigram/testing/plugins/pytest.py pytest plugin entry point
src/lexigram/testing/fixtures.py Auto-discovered pytest fixtures
src/lexigram/testing/clients/cache.py FakeCacheBackend
src/lexigram/testing/clients/db.py FakeDatabase
src/lexigram/testing/clients/events.py FakeEventBus, FakeCommandBus, FakeQueryBus
src/lexigram/testing/clients/tasks.py FakeTaskQueue
src/lexigram/testing/clients/ai.py FakeAIClient
src/lexigram/testing/data/__init__.py Factory helpers

Download files

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

Source Distribution

lexigram_testing-0.1.2.tar.gz (131.5 kB view details)

Uploaded Source

Built Distribution

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

lexigram_testing-0.1.2-py3-none-any.whl (200.6 kB view details)

Uploaded Python 3

File details

Details for the file lexigram_testing-0.1.2.tar.gz.

File metadata

  • Download URL: lexigram_testing-0.1.2.tar.gz
  • Upload date:
  • Size: 131.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for lexigram_testing-0.1.2.tar.gz
Algorithm Hash digest
SHA256 23fd0d1747f0b172fcfcda0339a1c5775ff0a05cc02f5ee20f091f082746da5a
MD5 2225096c034508b688a0a181dbef1514
BLAKE2b-256 d1ca8ebcf0bd98caf75f68e4e8bb886e31a707685872b4d2399f540d0b956aa1

See more details on using hashes here.

File details

Details for the file lexigram_testing-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for lexigram_testing-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 120ce8b9c48ced510c2c8e78eb4266efdd38d8ad29acad9d34773e0d68f792ff
MD5 5f49a90f83a772c8d05870f80eddf622
BLAKE2b-256 8cc14ad8024cf200b7822bc97eee3fdace237bb0fe6163971129f8358032c6fd

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.5008

1 file

0.1.5005

2 files

0.1.5002

2 files

0.1.5001

2 files

0.1.3007

1 file

0.1.3006

1 file

0.1.3005

1 file

0.1.4

2 files

This release

0.1.2 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page