Skip to main content

lexigram-testing

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


Overview

lexigram-testing provides in-process fakes for common framework protocols (FakeCache, FakeEventBus, FakeCommandBus, FakeClock, …), a pytest plugin with auto-registered fixtures, deterministic data-factory helpers, and a ContainerTestFixture for DI integration tests.


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
uv add --dev "lexigram-testing[auth]"    # lexigram-auth

Quick Start

import pytest
from lexigram.testing.fixtures import fake_cache
from lexigram.testing.fakes import FakeCache


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

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

    @pytest.mark.asyncio
    async def test_returns_cached_user(
        self, service: UserService, cache: FakeCache
    ) -> 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.testing.fakes import FakeEventBus


@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)

    fake_event_bus.assert_published(OrderPlaced, order_id=order.id)
    assert len(fake_event_bus.published_of_type(OrderPlaced)) == 1

Available Fakes

All fakes live in lexigram.testing.fakes and implement the async contracts of the real services.

Class Implements Location
FakeCache cache API (async get/set/delete/clear) lexigram.testing.fakes.cache
FakeEventBus in-process event bus; published(), published_of_type(), assert_published() lexigram.testing.fakes.events
FakeCommandBus command dispatch lexigram.testing.fakes.buses
FakeQueryBus query dispatch lexigram.testing.fakes.buses
FakeUnitOfWork unit-of-work context lexigram.testing.fakes.lifecycle
FakeClock deterministic clock lexigram.testing.fakes.clock
FakeConfig config overrides lexigram.testing.fakes.config
FakeLogger structlog-compatible logger lexigram.testing.fakes.logging
FakeMetricsCollector metrics recording lexigram.testing.fakes.monitoring
FakeStateStore state storage lexigram.testing.fakes.cache
FakeAuditLogger audit logging lexigram.testing.fakes.audit
FakeRotatableSecretStore secret storage with rotation lexigram.testing.fakes.secrets
FakeTracer / FakeSpan tracing lexigram.testing.fakes.tracing

Key Features

  • Zero infrastructure — all fakes run in-process; no Docker or external services needed
  • Assertion helpersassert_published(), assert_not_published(), assert_published_once(), assert_events_in_order()
  • Async-first — all fakes implement the same async APIs as real backends
  • pytest plugin — auto-registered fixtures and auto-skip for external-service markers (Redis, PostgreSQL, Elasticsearch, RabbitMQ, Meilisearch)
  • DB fixturesdatabase_provider, clean_database, db_transaction, mock_connection, sample_user_data (with [db] extra)
  • Data factorytest_data.create_user(), create_task(), create_message() via lexigram.testing.lib
  • Container fixtureContainerTestFixture with mock()/get() for DI integration tests
  • Reproducible — deterministic IDs and timestamps for snapshot testing

pytest Plugin

The plugin is loaded automatically via entry points — no manual wiring needed:

uv run pytest -m "not integration"   # unit tests only (fast)
uv run pytest -m integration         # integration tests

Tests marked with external-service markers (redis, postgres, elasticsearch, rabbitmq, meilisearch) are skipped automatically when the service is unreachable.

Key Source Files

File What it contains
src/lexigram/testing/plugins/pytest/ pytest plugin entry point, markers, auto-skip hooks
src/lexigram/testing/fixtures/core.py Auto-registered core fixtures (fake_cache, fake_event_bus, …)
src/lexigram/testing/fixtures/container.py ContainerTestFixture
src/lexigram/testing/fixtures/bed.py TestEnvironment builder (use_provider, override, fake)
src/lexigram/testing/fixtures/db.py DB fixtures (database_provider, clean_database, …)
src/lexigram/testing/fakes/events.py FakeEventBus
src/lexigram/testing/fakes/buses.py FakeCommandBus, FakeQueryBus
src/lexigram/testing/lib/factory.py TestDataFactory (create_user, create_task, …)

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.5001.tar.gz (192.1 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.5001-py3-none-any.whl (204.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lexigram_testing-0.1.5001.tar.gz
Algorithm Hash digest
SHA256 d3e093beac1c1d21d5fa83dc08b925b4ff593589b397dc725274952ee1a06d8a
MD5 4c8328b4e04a49da0f03fa56c9e32ec3
BLAKE2b-256 0e1d4dbc62dcbb5d62761eaaf695e011e03fd62817052b4610cb2e81c7e9c47b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lexigram_testing-0.1.5001-py3-none-any.whl
Algorithm Hash digest
SHA256 5fa87386adcbd465499dc14804f1dec62b37ca1206d5764ab089489377bd36c1
MD5 4cb25f2c2aa56fb9bf7ad048d3574f3c
BLAKE2b-256 c0fc702c9704190deb0c4a940c2190ca9338f779abdc0c6df12dce153a2ddd87

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

This release

0.1.5001 This release

2 files

0.1.3007

1 file

0.1.3006

1 file

0.1.3005

1 file

0.1.4

2 files

0.1.2

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