Skip to main content

Pytest plugin to verify PEP 723 inline script metadata covers all imports.

Project description

pytest-pep723

A pytest plugin that verifies PEP 723 inline script metadata covers all imports.

When you use uv run to dispatch scripts with inline metadata blocks like:

# /// script
# dependencies = [
#   "click",
#   "numpy",
# ]
# ///

...only the declared dependencies are available at runtime. If you add an import readcon but forget to add readcon to the deps block, the script fails at dispatch time. This plugin catches those gaps statically.

Installation

uv add --group dev pytest-pep723

Usage

# Scan all .py files under src/ for PEP 723 scripts
pytest --pep723-check --pep723-paths src/

# Ignore internal/conda-only packages
pytest --pep723-check --pep723-paths src/ --pep723-ignore mypkg --pep723-ignore ira_mod

Or configure in pyproject.toml:

[tool.pytest.ini_options]
pep723_paths =
    src/mypkg
pep723_ignore_imports =
    mypkg
    ira_mod
pep723_extra_mappings =
    gi=pygobject
    myspecial=my-special-pkg

Then just:

pytest --pep723-check

What it checks

For every .py file under the configured paths that contains a # /// script block:

  1. Parses the declared dependencies from inline metadata
  2. Extracts all import and from X import statements via AST
  3. Skips stdlib and ignored imports
  4. Maps import names to PyPI package names (handles PIL -> pillow, etc.)
  5. Reports any import not covered by the declared deps

Features

  • Handles multi-line and single-line dependency formats
  • Supports all version operators (>=, ~=, [extras], etc.)
  • Built-in mapping for 20+ packages where import name differs from pip name
  • Configurable ignore list for internal packages and conda-only deps
  • Custom import-to-package mappings via pep723_extra_mappings
  • Registers a pep723 marker for selective test runs

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

pytest_pep723-0.1.0.tar.gz (72.2 kB view details)

Uploaded Source

Built Distribution

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

pytest_pep723-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_pep723-0.1.0.tar.gz.

File metadata

  • Download URL: pytest_pep723-0.1.0.tar.gz
  • Upload date:
  • Size: 72.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_pep723-0.1.0.tar.gz
Algorithm Hash digest
SHA256 563d8268b942002c576ae24f75ce708725d42e5b1dad191c353f5ae120d0fae1
MD5 1eba0c6e5e5aad4ca16ce095adcc7774
BLAKE2b-256 41dcacdca797b621dd84112666308b304777a0afeb9a72c3da5b4d73ff3021f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_pep723-0.1.0.tar.gz:

Publisher: release.yml on HaoZeke/pytest-pep723

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

File details

Details for the file pytest_pep723-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_pep723-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_pep723-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63b91ddc3704d544a359d7a46131c4c3e8447e8a3ec912715694813b1c2a7c5f
MD5 7e4cb1b64309ebcd739c0547345485d6
BLAKE2b-256 8bbb337b91e3657295753fd0a40f3446ff59d5a68a3131e6336122ae235c3979

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_pep723-0.1.0-py3-none-any.whl:

Publisher: release.yml on HaoZeke/pytest-pep723

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