Pytest plugin for the Pico ecosystem: isolated containers by default and a make_container fixture.
Project description
pico-testing
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=falseis 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 FastAPITestClientover 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 toinit(modules=[...]).config: a plain dict (wrapped inconfiguration(DictSource(...))) or a readyconfiguration(...)object.boot=True: usepico_boot.initinstead ofpico_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40feefc049f1f9d09cf093066ec0c104e56ff106a7b161f1a6b827716b804ce1
|
|
| MD5 |
12ad23952a30ed1a611df69516f79dab
|
|
| BLAKE2b-256 |
49968d6c3a2db49bd85a1ff5b7a51608770779718114c084efb873c6f34d4e26
|
Provenance
The following attestation bundles were made for pico_testing-0.2.0.tar.gz:
Publisher:
publish-to-pypi.yml on dperezcabrera/pico-testing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pico_testing-0.2.0.tar.gz -
Subject digest:
40feefc049f1f9d09cf093066ec0c104e56ff106a7b161f1a6b827716b804ce1 - Sigstore transparency entry: 2141755962
- Sigstore integration time:
-
Permalink:
dperezcabrera/pico-testing@ba329608bad76a38e9113e51c56009a240e2d76e -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/dperezcabrera
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ba329608bad76a38e9113e51c56009a240e2d76e -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0b8371637cb350eff9dc23fbe3989d326655eb2230b27d7f0f4ea948386a901
|
|
| MD5 |
2b94481496f6094f7c89d3a1814b3f9b
|
|
| BLAKE2b-256 |
f0e4a9af1310819a9047e0ad17a7f3656d2d9ad8ffd2eeee1317be204b8985f3
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pico_testing-0.2.0-py3-none-any.whl -
Subject digest:
d0b8371637cb350eff9dc23fbe3989d326655eb2230b27d7f0f4ea948386a901 - Sigstore transparency entry: 2141755995
- Sigstore integration time:
-
Permalink:
dperezcabrera/pico-testing@ba329608bad76a38e9113e51c56009a240e2d76e -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/dperezcabrera
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ba329608bad76a38e9113e51c56009a240e2d76e -
Trigger Event:
release
-
Statement type: