Skip to main content

Testing marimo Notebooks

marimo notebooks are pure Python, making them fully testable with standard Python testing frameworks. marimo provides first-class pytest integration with reactive test execution.

Quick Start

Create a notebook with test functions:
Run tests interactively in the editor or via CLI:

Reactive Test Execution

marimo can automatically run pytest on cells containing test functions:
When enabled:
  • Cells with only test functions/classes are automatically tested
  • Test results appear inline in the notebook
  • Tests re-run when dependencies change

Writing Tests

Basic Test Functions

Testing Functions Defined in Notebooks

Use @app.function to define testable functions:

Parametrized Tests

Test Classes

Running Tests

In the marimo Editor

With reactive_tests: True, test cells automatically execute and display results:

Using pytest CLI

Run tests using pytest directly:

Programmatic Test Execution

From marimo/_runtime/pytest.py, you can run tests programmatically:

Test Fixtures

Cell-Level Fixtures

Define fixtures in the same cell as tests:

Shared Fixtures

Define fixtures in a separate cell for reuse:

Integration Testing

Testing Data Pipelines

Testing UI Components

Testing Best Practices

Keep test cells independent and focused:
Follow pytest conventions for test naming:
Cover boundary conditions and error cases:
Avoid duplication with pytest fixtures:

Running Doctests

marimo supports running doctests in notebook cells:

Test Configuration

Configure pytest behavior in pyproject.toml:

CI/CD Integration

Run notebook tests in continuous integration:

Example: Complete Test Suite

From examples/testing/test_with_pytest.py:

Debugging Failed Tests

When tests fail, marimo provides detailed tracebacks: