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
fix: address windows flakiness by reducing introspection calls (#7678)
Dylan Madisetti968f3f880881
diff --git a/marimo/_ast/pytest.py b/marimo/_ast/pytest.pyindex 0ef733bea6..cb30d8ae0a 100644--- a/marimo/_ast/pytest.py+++ b/marimo/_ast/pytest.py@@ -16,6 +16,7 @@ from marimo._runtime.context import ContextNotInitializedError, get_contextif TYPE_CHECKING:from collections.abc import Mapping+ from inspect import FrameInfoFn = TypeVar("Fn", bound=Callable[..., Any])@@ -282,6 +283,7 @@ def build_test_class(file: str,name: str,defs: set[str],+ frames: list[FrameInfo],inner: bool = False,) -> type[MarimoTest]:"""@@ -343,7 +345,6 @@ def build_test_class(# If not in runtime, we are running directly as a script. As# such, we need the values from the module frame.# Traverse frame upwards until we match the file.- frames = inspect.stack(context=0)for frame in frames:if Path(frame.filename).resolve() == Path(file).resolve():base_local.update(frame.frame.f_locals)@@ -387,7 +388,7 @@ def build_test_class(return old_output, old_defsreturn build_test_class(- test.body, _run, file, var, class_defs, True+ test.body, _run, file, var, class_defs, frames, True)raise ValueError("Improperly compiled as a test. Please report to"@@ -425,14 +426,14 @@ def process_for_pytest(func: Fn, cell: Cell) -> None:raise ValueError(f"Expected function or class definition, got {type(scope).__name__}")- cls = build_test_class(- scope.body, run, inspect.getfile(func), name, cell.defs- )-# Get first frame not in library to insert the class.# May be multiple levels if called from pytest or something.frames = inspect.stack(context=0)+ cls = build_test_class(+ scope.body, run, inspect.getfile(func), name, cell.defs, frames+ )+# ensure marimo/_ not in frame path, using this file as a reference.library = Path(__file__).parent.parentfor frame in frames:diff --git a/pixi.lock b/pixi.lockindex 7683cc9d81..a54a1bd6fc 100644--- a/pixi.lock+++ b/pixi.lock@@ -5,6 +5,8 @@ environments:- url: https://conda.anaconda.org/conda-forge/indexes:- https://pypi.org/simple+ options:+ pypi-prerelease-mode: if-necessary-or-explicitpackages:linux-64:- conda: https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2@@ -116,7 +118,7 @@ environments:- pypi: https://files.pythonhosted.org/packages/79/3e/b8ecc67e178919671695f64374a7ba916cf0adbf86efedc6054f38b5b8ae/narwhals-2.14.0-py3-none-any.whl- pypi: https://files.pythonhosted.org/packages/16/32/f8e3c85d1d5250232a5d3477a2a28cc291968ff175caeadaf3cc19ce0e4a/parso-0.8.5-py2.py3-none-any.whl- pypi: https://files.pythonhosted.org/packages/29/f8/40e01c350ad9a2b3cb4e6adbcc8a83b17ee50dd5792102b6142385937db5/psutil-7.2.1-cp36-abi3-manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_28_x86_64.whl- - pypi: https://files.pythonhosted.org/packages/fb/35/b763e8fbcd51968329b9adc52d188fc97859f85f2ee15fe9f379987d99c5/pymdown_extensions-10.19.1-py3-none-any.whl+ - pypi: https://files.pythonhosted.org/packages/ea/10/47caf89cbb52e5bb764696fd52a8c591a2f0e851a93270c05a17f36000b5/pymdown_extensions-10.20-py3-none-any.whl- pypi: https://files.pythonhosted.org/packages/d9/52/1064f510b141bd54025f9b55105e26d1fa970b9be67ad766380a3c9b74b0/starlette-0.50.0-py3-none-any.whl- pypi: https://files.pythonhosted.org/packages/3d/d8/2083a1daa7439a66f3a48589a57d576aa117726762618f6bb09fe3798796/uvicorn-0.40.0-py3-none-any.whl- pypi: https://files.pythonhosted.org/packages/14/8f/aa61f528fba38578ec553c145857a181384c72b98156f858ca5c8e82d9d3/websockets-15.0.1-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl@@ -214,7 +216,7 @@ environments:- pypi: https://files.pythonhosted.org/packages/79/3e/b8ecc67e178919671695f64374a7ba916cf0adbf86efedc6054f38b5b8ae/narwhals-2.14.0-py3-none-any.whl- pypi: https://files.pythonhosted.org/packages/16/32/f8e3c85d1d5250232a5d3477a2a28cc291968ff175caeadaf3cc19ce0e4a/parso-0.8.5-py2.py3-none-any.whl- pypi: https://files.pythonhosted.org/packages/c5/2c/78e4a789306a92ade5000da4f5de3255202c534acdadc3aac7b5458fadef/psutil-7.2.1-cp36-abi3-macosx_11_0_arm64.whl- - pypi: https://files.pythonhosted.org/packages/fb/35/b763e8fbcd51968329b9adc52d188fc97859f85f2ee15fe9f379987d99c5/pymdown_extensions-10.19.1-py3-none-any.whl+ - pypi: https://files.pythonhosted.org/packages/ea/10/47caf89cbb52e5bb764696fd52a8c591a2f0e851a93270c05a17f36000b5/pymdown_extensions-10.20-py3-none-any.whl- pypi: https://files.pythonhosted.org/packages/d9/52/1064f510b141bd54025f9b55105e26d1fa970b9be67ad766380a3c9b74b0/starlette-0.50.0-py3-none-any.whl- pypi: https://files.pythonhosted.org/packages/3d/d8/2083a1daa7439a66f3a48589a57d576aa117726762618f6bb09fe3798796/uvicorn-0.40.0-py3-none-any.whl- pypi: https://files.pythonhosted.org/packages/3d/69/1a681dd6f02180916f116894181eab8b2e25b31e484c5d0eae637ec01f7c/websockets-15.0.1-cp312-cp312-macosx_11_0_arm64.whl@@ -1131,7 +1133,7 @@ packages:- pypi: ./name: marimoversion: 0.18.4- sha256: 75d33a687eaea5b9293810fe11e6cb3d633b7b0ac04ebbe063855dd3f7fc9437+ sha256: 1db0ec3fd3a5aaad887dcd9c1fe56a2791af8a584a5f266799cf9a3dd50f7a78requires_dist:- click>=8.0,<9- jedi>=0.18.0@@ -1164,7 +1166,6 @@ packages:- mcp>=1.0.0 ; extra == 'mcp'- pydantic>2 ; extra == 'mcp'requires_python: '>=3.10'- editable: true- pypi: https://files.pythonhosted.org/packages/70/81/54e3ce63502cd085a0c556652a4e1b919c45a446bd1e5300e10c44c8c521/markdown-3.10-py3-none-any.whlname: markdownversion: '3.10'@@ -1589,10 +1590,10 @@ packages:- pkg:pypi/pygments?source=hash-mappingsize: 889287timestamp: 1750615908735-- pypi: https://files.pythonhosted.org/packages/fb/35/b763e8fbcd51968329b9adc52d188fc97859f85f2ee15fe9f379987d99c5/pymdown_extensions-10.19.1-py3-none-any.whl+- pypi: https://files.pythonhosted.org/packages/ea/10/47caf89cbb52e5bb764696fd52a8c591a2f0e851a93270c05a17f36000b5/pymdown_extensions-10.20-py3-none-any.whlname: pymdown-extensions- version: 10.19.1- sha256: e8698a66055b1dc0dca2a7f2c9d0ea6f5faa7834a9c432e3535ab96c0c4e509b+ version: '10.20'+ sha256: ea9e62add865da80a271d00bfa1c0fa085b20d133fb3fc97afdc88e682f60b2frequires_dist:- markdown>=3.6- pyyamldiff --git a/pyproject.toml b/pyproject.tomlindex 48c9810dda..071f0cdf21 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -503,6 +503,7 @@ testpaths = ["tests"]asyncio_mode = "auto"asyncio_default_fixture_loop_scope = "function"timeout = 30 # seconds, per test+faulthandler_timeout = 30 # seconds, during collection[tool.coverage.run]omit = ["marimo/_tutorials/*"]diff --git a/tests/conftest.py b/tests/conftest.pyindex 7a4e94df79..6e41b4c552 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -663,66 +663,70 @@ def pytest_make_collect_report(collector):# Defined within the file does not seem to hook correctly, as such filter# for the test_pytest specific file here.- if "test_pytest" in str(collector.path) and "_ast" in str(collector.path):- # Classes may also be registered, but they will be hidden behind a cell.- # As such, let's just collect functions.- collected = {- fn.originalname- for fn in collector.collect()- if isinstance(fn, pytest.Function)- }- classes = {- cls.name- for cls in collector.collect()- if isinstance(cls, pytest.Class)- }- from tests._ast.test_pytest import app as app_pytest- from tests._ast.test_pytest_scoped import app as app_scoped- from tests._ast.test_pytest_toplevel import app as app_toplevel-- app = {- "test_pytest": app_pytest,- "test_pytest_toplevel": app_toplevel,- "test_pytest_scoped": app_scoped,- }[collector.path.stem]-- # Just a quick check to make sure the class is actually exported.- if app == app_pytest:- if len(classes) == 0:- report.outcome = "failed"- report.longrepr = (- f"Expected class in {collector.path}, found none "- " (tests/conftest.py)."- )- return report- for cls in classes:- if not (- cls.startswith("MarimoTestBlock")- or cls- in (- "TestClassWorks",- "TestClassWithFixtures",- "TestClassDefinitionWithFixtures",- )- ):- report.outcome = "failed"- report.longrepr = (- f"Unknown class '{cls}' in {collector.path}"- " (tests/conftest.py)."- )-- return report-- # Check the functions match cells in the app.- invalid = []- for name in app._cell_manager.names():- if name.startswith("test_") and name not in collected:- invalid.append(f"'{name}'")- if invalid:- tests = ", ".join([f"'{test}'" for test in collected])+ if not (+ "test_pytest" in str(collector.path) and "_ast" in str(collector.path)+ ):+ return report++ # Classes may also be registered, but they will be hidden behind a cell.+ # As such, let's just collect functions.+ collected = {+ fn.originalname+ for fn in collector.collect()+ if isinstance(fn, pytest.Function)+ }+ classes = {+ cls.name+ for cls in collector.collect()+ if isinstance(cls, pytest.Class)+ }+ from tests._ast.test_pytest import app as app_pytest+ from tests._ast.test_pytest_scoped import app as app_scoped+ from tests._ast.test_pytest_toplevel import app as app_toplevel++ app = {+ "test_pytest": app_pytest,+ "test_pytest_toplevel": app_toplevel,+ "test_pytest_scoped": app_scoped,+ }[collector.path.stem]++ # Just a quick check to make sure the class is actually exported.+ if app == app_pytest:+ if len(classes) == 0:report.outcome = "failed"report.longrepr = (- f"Cannot collect test(s) {', '.join(invalid)} from {tests}"+ f"Expected class in {collector.path}, found none "" (tests/conftest.py).")+ return report+ for cls in classes:+ if not (+ cls.startswith("MarimoTestBlock")+ or cls+ in (+ "TestClassWorks",+ "TestClassWithFixtures",+ "TestClassDefinitionWithFixtures",+ )+ ):+ report.outcome = "failed"+ report.longrepr = (+ f"Unknown class '{cls}' in {collector.path}"+ " (tests/conftest.py)."+ )++ return report++ # Check the functions match cells in the app.+ invalid = []+ for name in app._cell_manager.names():+ if name.startswith("test_") and name not in collected:+ invalid.append(f"'{name}'")+ if invalid:+ tests = ", ".join([f"'{test}'" for test in collected])+ report.outcome = "failed"+ report.longrepr = (+ f"Cannot collect test(s) {', '.join(invalid)} from {tests}"+ " (tests/conftest.py)."+ )return report