Skip to main content

Pytest plugin for the Pico ecosystem: isolated containers by default and a make_container fixture.

Project description

pico-testing

PyPI Ask DeepWiki License: MIT CI (tox matrix) codecov Quality Gate Status Duplicated Lines (%) Maintainability Rating PyPI Downloads Docs Interactive Lab

Pytest plugin for the pico ecosystem: isolated containers by default and a make_container fixture with automatic shutdown.

Why

Any pico_boot.init() in a test auto-discovers every pico plugin installed in the venv — so a test suite passes or fails depending on what else happens to be installed. Every pico project ends up copying the same two conftest fixtures. This plugin ships them once:

  • Isolation by default: PICO_BOOT_AUTO_PLUGINS=false is set for every test. Opt back in per-test with @pytest.mark.pico_auto_plugins.
  • make_container: builds containers from explicit modules and config, and shuts them all down on teardown.
  • pico_module: declare the package under test once in your pytest config; make_container() always includes it.
  • make_client: a FastAPI TestClient over a container's app, with the lifespan running and a safe close on teardown.

Installation

pip install pico-testing

No conftest wiring — installing it activates the plugin.

Quick start

import sys

def test_my_service(make_container):
    container = make_container(
        "my_package",
        config={"my_prefix": {"key": "value"}},
    )
    service = container.get(MyService)
    assert service.do_something() == "expected"

make_container(*modules, config=None, boot=False):

  • modules: module objects or import strings, passed to init(modules=[...]).
  • config: a plain dict (wrapped in configuration(DictSource(...))) or a ready configuration(...) object.
  • boot=True: use pico_boot.init instead of pico_ioc.init (plugin auto-discovery still off unless the test is marked).

Re-enable plugin auto-discovery for a single test:

import pytest

@pytest.mark.pico_auto_plugins
def test_full_boot(make_container):
    container = make_container(boot=True)

Module under test

Declare it once and drop it from every call:

# pyproject.toml
[tool.pytest.ini_options]
pico_module = "my_package"
def test_my_service(make_container):
    service = make_container().get(MyService)

Testing HTTP endpoints

With pico-fastapi installed, make_client wraps the container's app in a TestClient with the lifespan running (requires pico-ioc >= 2.3.3):

def test_endpoint(make_container, make_client):
    container = make_container("pico_fastapi", config={"fastapi": {"title": "t"}})
    client = make_client(container)
    assert client.get("/ping").status_code == 200

Documentation

Full documentation: https://dperezcabrera.github.io/pico-testing/

AI Coding Skills

Install Claude Code or OpenAI Codex skills for AI-assisted development with pico-testing:

curl -sL https://raw.githubusercontent.com/dperezcabrera/pico-skills/main/install.sh | bash

The pico-conventions skill teaches the assistant this module's API surface and invariants; /add-component and /add-tests scaffold components and tests that use it.

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

pico_testing-0.2.0.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

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

pico_testing-0.2.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file pico_testing-0.2.0.tar.gz.

File metadata

  • Download URL: pico_testing-0.2.0.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pico_testing-0.2.0.tar.gz
Algorithm Hash digest
SHA256 40feefc049f1f9d09cf093066ec0c104e56ff106a7b161f1a6b827716b804ce1
MD5 12ad23952a30ed1a611df69516f79dab
BLAKE2b-256 49968d6c3a2db49bd85a1ff5b7a51608770779718114c084efb873c6f34d4e26

See more details on using hashes here.

Provenance

The following attestation bundles were made for pico_testing-0.2.0.tar.gz:

Publisher: publish-to-pypi.yml on dperezcabrera/pico-testing

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

File details

Details for the file pico_testing-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pico_testing-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pico_testing-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0b8371637cb350eff9dc23fbe3989d326655eb2230b27d7f0f4ea948386a901
MD5 2b94481496f6094f7c89d3a1814b3f9b
BLAKE2b-256 f0e4a9af1310819a9047e0ad17a7f3656d2d9ad8ffd2eeee1317be204b8985f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pico_testing-0.2.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on dperezcabrera/pico-testing

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