Small cli that allows for more elborate testing inside Marimo
Project description
motest
Small cli that allows for more elaborate testing inside Marimo
This project was made so I might more easily write elaborate tests in side of Marimo notebooks. It is barely worth the effort because you can also just add the commands together in a Makefile, but it was a fun exercise that led me to learn how pytest can be called directly from Python.
Installation
uv pip install motest
Usage
Suppose that you have a notebook some_notebook.py that you want to test. Maybe with the following content:
import marimo as mo
import pytest
def add(a, b):
return a + b
@pytest.mark.parametrize("a,b,c", [(1, 1, 2), (1, 2, 3)])
def test_add(a, b, c):
assert add(a, b) == c
You can test this notebook by running the following command:
python -m motest some_notebook.py
This is what the output will look like:
============================= test session starts ==============================
platform darwin -- Python 3.10.14, pytest-8.3.4, pluggy-1.5.0
rootdir: /Users/vincent/Development/motest
configfile: pyproject.toml
plugins: anyio-4.7.0
collected 2 items
test_some_notebook.py .. [100%]
============================== 2 passed in 0.11s ===============================
How it works
The setup is really minimal. We call the marimo export script command and write the Python code to a temporary file. We then point pytest to this file and do a cleanup after the tests are done. The status code is returned to the caller and you are also able to pass any pytest arguments to the command as well.
You could accomplish the same thing by adding this to a Makefile:
test:
marimo export script -o test_some_notebook.py some_notebook.py
python -m pytest test_some_notebook.py
But it kind of felt nicer to have a dedicated command for this.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file motest-0.1.1.tar.gz.
File metadata
- Download URL: motest-0.1.1.tar.gz
- Upload date:
- Size: 30.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7620e787d814133c5d1a4bbf2e7122118b961069f9f35568b0dfa46b5f65289
|
|
| MD5 |
9fb065079919ae39999f9b062bc35ce9
|
|
| BLAKE2b-256 |
91255dae003f491df1d2b0771ddbaddbf07b7eca648102257c6d728a582791f9
|
File details
Details for the file motest-0.1.1-py2.py3-none-any.whl.
File metadata
- Download URL: motest-0.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
757b95e4cb3df9794a932c7ce0d70fdd3becd77e01dcd9131ef6270bf6321a0d
|
|
| MD5 |
ccc52f85dbf93637cd4280b34b7c7fe8
|
|
| BLAKE2b-256 |
172b2cc0dd6b5edb419c147d98df31e5bd8ea18acf53af5ffe5523723a52e8cc
|