Metadata-Version: 2.4
Name: pico-testing
Version: 0.2.0
Summary: Pytest plugin for the Pico ecosystem: isolated containers by default and a make_container fixture.
Author-email: David Perez Cabrera <dperezcabrera@gmail.com>
License: MIT License
        
        Copyright (c) 2025 David Pérez Cabrera
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/dperezcabrera/pico-testing
Project-URL: Documentation, https://dperezcabrera.github.io/pico-testing/
Project-URL: Repository, https://github.com/dperezcabrera/pico-testing
Project-URL: Changelog, https://github.com/dperezcabrera/pico-testing/blob/main/CHANGELOG.md
Project-URL: Issue Tracker, https://github.com/dperezcabrera/pico-testing/issues
Keywords: testing,pytest,fixtures,ioc,dependency injection,spring boot
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Pytest
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pico-ioc>=2.3.3
Requires-Dist: pytest>=8
Provides-Extra: dev
Requires-Dist: pytest-asyncio; extra == "dev"
Requires-Dist: pytest-cov>=5; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: pico-boot>=0.1.0; extra == "dev"
Dynamic: license-file

# pico-testing

[![PyPI](https://img.shields.io/pypi/v/pico-testing.svg)](https://pypi.org/project/pico-testing/)
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/dperezcabrera/pico-testing)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
![CI (tox matrix)](https://github.com/dperezcabrera/pico-testing/actions/workflows/ci.yml/badge.svg)
[![codecov](https://codecov.io/gh/dperezcabrera/pico-testing/branch/main/graph/badge.svg)](https://codecov.io/gh/dperezcabrera/pico-testing)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=dperezcabrera_pico-testing&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-testing)
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=dperezcabrera_pico-testing&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-testing)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=dperezcabrera_pico-testing&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=dperezcabrera_pico-testing)
[![PyPI Downloads](https://img.shields.io/pypi/dm/pico-testing)](https://pypi.org/project/pico-testing/)
[![Docs](https://img.shields.io/badge/Docs-pico--testing-blue?style=flat&logo=readthedocs&logoColor=white)](https://dperezcabrera.github.io/pico-testing/)
[![Interactive Lab](https://img.shields.io/badge/Learn-online-green?style=flat&logo=python&logoColor=white)](https://dperezcabrera.github.io/pico-learn/)

Pytest plugin for the [pico ecosystem](https://github.com/dperezcabrera/pico-ioc): 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

```bash
pip install pico-testing
```

No conftest wiring — installing it activates the plugin.

## Quick start

```python
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:

```python
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:

```toml
# pyproject.toml
[tool.pytest.ini_options]
pico_module = "my_package"
```

```python
def test_my_service(make_container):
    service = make_container().get(MyService)
```

## Testing HTTP endpoints

With [pico-fastapi](https://github.com/dperezcabrera/pico-fastapi) installed, `make_client` wraps the container's app in a `TestClient` with the lifespan running (requires pico-ioc >= 2.3.3):

```python
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](https://code.claude.com) or [OpenAI Codex](https://openai.com/index/introducing-codex/) skills for AI-assisted development with pico-testing:

```bash
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
