Get help from the marimo community

Updated 2 months ago

pytest - best practices

At a glance

The community member is seeking the best practices for running pytest tests within a Marimo notebook. They are unable to run pytest.main() within the notebook and running tests in the command line is also not working. The community members discuss potential approaches, such as using asserts in individual cells or embedding tests in functions and using pytest. One community member suggests using docstrings for testing and provides a link to an example notebook. However, there is no explicitly marked answer in the comments.

Useful resources
I was wondering what the best practices are related to pytest. I can't run pytest.main() within the marimo notebook (error); and running it in the command line is not working neither (I guess I would have to export it into a classical python file first. Is there a recommend best approach to run tests?
A
s
M
4 comments
Haven’t actually tried implementing tests within a marimo notebook — is that what you’re doing?
That’s an interesting idea and something we could look into if so
yes, I would like to add some asserts while developing but I am not sure how to run them; one approach is to have the assert in one cell, but I would like to embed them into a function and use pytest. Maybe it could be a widget (like Explore Variables) that would run pytest?
@svolt863 we had a user use docstrings for testing - you can check out this half-example notebook:
https://github.com/marimo-team/marimo/blob/9a2dee666e157677e2b768064628c3d3c18bd854/marimo/_smoke_tests/doctests.py#L58
Add a reply
Sign up and join the conversation on Discord