Skip to main content

Fixture Foundry

Pytest fixtures and context managers for ephemeral integration testing infrastructure: LocalStack (AWS services), PostgreSQL containers, and Pulumi deployment automation.

Features

  • Session-scoped fixtures: localstack, postgres, container_network
  • Context managers: Standalone infrastructure orchestration for dev scripts
  • Pulumi Automation: deploy() helper targets LocalStack automatically
  • Database seeding: exec_sql_file() loads SQL schemas with transaction support
  • URL translation: to_localstack_url() converts AWS Gateway URLs to LocalStack endpoints
  • Auto-cleanup: Health checks, retries, and teardown on test completion

Installation

pip install fixture-foundry docker requests pytest psycopg2-binary
# Optional for Pulumi deployment:
pip install pulumi pulumi-aws

Requirements: Python 3.8–3.12, Docker

Quick Start

Setup pytest fixtures in conftest.py

import pytest
from fixture_foundry import localstack, postgres, container_network  # noqa: F401

def pytest_addoption(parser):
    g = parser.getgroup("localstack")
    g.addoption("--teardown", default="true")
    g.addoption("--localstack-port", type=int, default=0)  # 0 = random port
    g.addoption("--database-image", default="postgres:16")

Database with Schema Loading

from pathlib import Path
import psycopg2
from fixture_foundry import postgres, exec_sql_file

@pytest.fixture(scope="session")
def test_db(postgres):
    # Load schema from SQL file
    schema_file = Path(__file__).parent / "schema.sql"
    
    conn = psycopg2.connect(postgres["dsn"])
    conn.autocommit = True  # Required for multi-statement scripts
    exec_sql_file(conn, schema_file)
    conn.close()
    
    yield postgres

Pulumi Deployment to LocalStack

import json
from fixture_foundry import deploy, to_localstack_url

def my_pulumi_program():
    # Your Pulumi resources here
    pulumi.export("api_url", "https://example.execute-api.us-east-1.amazonaws.com")

@pytest.fixture(scope="module") 
def api_stack(test_db, localstack):
    with deploy("my-project", "test", my_pulumi_program, localstack=localstack) as outputs:
        yield outputs

@pytest.fixture(scope="module")
def api_endpoint(api_stack, localstack):
    # Convert AWS Gateway URL to LocalStack endpoint
    aws_url = api_stack["api_url"]
    yield to_localstack_url(aws_url, localstack["port"])

def test_api_call(api_endpoint):
    import requests
    response = requests.get(f"{api_endpoint}/health")
    assert response.status_code == 200

Context Managers (for dev scripts)

from pathlib import Path
import psycopg2
from fixture_foundry import postgres_context, localstack_context, deploy, exec_sql_file

# Standalone usage outside pytest
with postgres_context(database="mydb") as pg:
    # Seed database with schema
    conn = psycopg2.connect(pg["dsn"])
    conn.autocommit = True
    exec_sql_file(conn, Path("schema.sql"))
    conn.close()
    
    with localstack_context() as ls:
        with deploy("proj", "stack", program, localstack=ls) as outputs:
            # Infrastructure is now running - execute your dev workflow
            api_url = outputs['endpoint']
            print(f"API deployed at: {api_url}")
            
            # Start frontend dev server, run manual tests, etc.
            # subprocess.run(["npm", "run", "dev"], env={"VITE_API_URL": api_url})
            # Or keep running for interactive development...

API Reference

Fixtures (session-scoped)

Fixture Yields Description
container_network str Docker bridge network name (default: "ls-dev")
postgres dict PostgreSQL container with dsn, host_port, container_name, credentials
localstack dict LocalStack container with endpoint_url, port, region, services

Functions

Function Purpose
deploy(project, stack, program, localstack=None, teardown=True) Pulumi Automation API context manager
exec_sql_file(conn, path) Execute SQL file (supports multi-statement, DO $$ blocks)
to_localstack_url(aws_url, edge_port=4566) Convert AWS Gateway URL to LocalStack endpoint

Connection Patterns

  • Container-to-container: Use postgres["container_name"]:5432 (Docker network)
  • Host-to-container: Use localhost:{postgres["host_port"]} (port mapping)
  • Lambda-to-DB: Requires shared Docker network (automatic with LocalStack)

Environment Variables

  • AWS_REGION / AWS_DEFAULT_REGION: AWS region (default: us-east-1)
  • DOCKER_TEST_NETWORK: Override network name (default: ls-dev)
  • LAMBDA_DOCKER_NETWORK: Set by LocalStack for container connectivity

CLI Options

Add to your conftest.py via pytest_addoption():

  • --teardown=true|false: Control resource cleanup
  • --localstack-port=0: LocalStack port (0 = random)
  • --database-image=postgres:16: PostgreSQL Docker image
  • --localstack-image=localstack/localstack:latest: LocalStack image

Metadata

Release files for fixture-foundry 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fixture-foundry 0.2.4
File Size Uploaded Provenance Actions
fixture_foundry-0.2.4.tar.gz 26.9 kB Without provenance Details for fixture_foundry-0.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fixture-foundry 0.2.4
File Interpreter ABI Platform Actions
fixture_foundry-0.2.4-py3-none-any.whl Python 3 none any Details for fixture_foundry-0.2.4-py3-none-any.whl

Total release size: 43.5 kB

Release files / fixture_foundry-0.2.4.tar.gz

Download URL fixture_foundry-0.2.4.tar.gz
Size 26.9 kB
Tags Source
SHA-256 checksum
How to use checksums
69a7cdf11869005308c1026cca3b4e49c33cf4e7ad95ab8ad27b8904e8702b6e
BLAKE2b-256 checksum
How to use checksums
1914ebec0fefb9ce74f5fd9b8e6fbd7c1b19b3a32713683f53d32854e4003096
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release files / fixture_foundry-0.2.4-py3-none-any.whl

Download URL fixture_foundry-0.2.4-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
be23e5d8de0440a600780b7d837f0f2669b48d1e04a2be38f88662f6d8cfafac
BLAKE2b-256 checksum
How to use checksums
dce74e777057864ff895b64d5396e1da6ab7763b8590497f3e3a89e24262edb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Security for fixture-foundry 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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