A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
docs: clarify tests should be exclusive in cells (#4491)
Dylan Madisetti0d3f79178967
diff --git a/docs/guides/testing/pytest.md b/docs/guides/testing/pytest.mdindex 2dac685338..c20e11248f 100644--- a/docs/guides/testing/pytest.md+++ b/docs/guides/testing/pytest.md@@ -2,10 +2,12 @@## Testing in notebook-By default, marimo detects and runs tests in your notebooks automatically. If-the optional `pytest` library is installed, marimo will run `pytest` on any cells that-contain test functions (functions that start with `test_`) or test classes-(classes that start with `Test`) on a per cell basis.+By default, marimo discovers and executes tests inside your notebook.+When the optional `pytest` dependency is present, marimo runs `pytest` on cells that+consist exclusively of test code - i.e. functions whose names start with `test_` or+classes whose names start with `Test`. If a cell mixes in anything else (helper+functions, constants, variables, imports, etc.), that cell is skipped by the test+runner (we recommend you move helpers to another cell).For example,@@ -21,16 +23,18 @@ def __():@app.celldef __(inc, pytest):- def test_fails():- assert inc(3) == 5, "This test fails"+ class TestBlock:+ @staticmethod+ def test_fails():+ assert inc(3) == 5, "This test fails"- def test_sanity():- assert inc(3) == 4, "This test passes"+ @staticmethod+ def test_sanity():+ assert inc(3) == 4, "This test passes"- class TestBlock:- @pytest.mark.parametrize(("x", "y"), [(3, 4), (4, 5)])- def test_parameterized(x, y):- assert inc(x) == y+ @pytest.mark.parametrize(("x", "y"), [(3, 4), (4, 5)])+ def test_parameterized(x, y):+ assert inc(x) == yreturn```@@ -54,7 +58,7 @@ pytest test_notebook.py```runs and tests all notebook cells whose names start with `test_`, or cells that-contain only `test_` functions and `Test` classes.+contain only `test_` functions and `Test` classes (just like in notebook tests).!!! tip "Naming cells"