Skip to main content

Pytest

Official module: dagger/pytest

Install with dagger mod install github.com/dagger/pytest.

What It Is​

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.

Use It For​

  • Add a Python test check to a workspace.
  • Run tests from a standard source directory.
  • Use a custom Python container when the default environment is not enough.

Main Workflow​

  • test: run Pytest against the project source.

How to Use It​

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.

Settings​

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"

Test options​

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.

Workspace Fit​

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​

Source repo: github.com/dagger/pytest