docs/current_docs/modules/pytest.mdx
Official module: dagger/pytest
Install with dagger mod install github.com/dagger/pytest.
The Pytest module runs Python tests with Pytest.
Use it when your workspace already has Python tests and you want them to run the same way locally, in CI, and in Dagger Cloud.
test: run Pytest against the project source.Install the module, then run its check:
dagger mod install github.com/dagger/pytest
dagger check # run every check in the workspace
dagger check pytest:test # run Pytest against the project source
test injects pytest_otel automatically, so individual Python tests appear as spans in the Dagger TUI and Dagger Cloud with no project changes. Dependencies are installed from the project itself: uv run for pyproject.toml projects, or pip install -r requirements.txt for requirements-based projects.
List the current settings and their values with dagger settings pytest, then set one with dagger settings pytest <key> <value>. Settings are stored in .dagger/config.toml under [modules.pytest.settings].
source (default: workspace root): the directory containing the Python project to test. Point it at a subdirectory when the project is not at the workspace root.container (default: none): a custom container that already has Python and uv installed. By default the module uses an Alpine base and provisions Python with uv; set a container when tests need system packages, a private index, or other setup the default image lacks.[modules.pytest.settings]
source = "./service"
The pytest:test check runs with default options. Call the test function directly with dagger function call to override them:
version (default 3.14): the Python version the default container provisions, such as 3.13 or 3.12. Ignored when a custom container is set, since that container's Python is used as-is.args (default ["-v"]): arguments passed straight to pytest, such as ["-x", "--tb=short"].Keep this module focused on tests; use separate modules for formatting, linting, shell scripts, or generated files.
This module is a good first check for Python repos. Once it passes locally, it is a natural candidate for autocheck and PR validation.
Source repo: github.com/dagger/pytest