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: allow test cells in the presence of async cells (#6355)
Dylan Madisetti0076848871a8
diff --git a/marimo/_ast/pytest.py b/marimo/_ast/pytest.pyindex 2a5ec8b57a..2bc38fc6bb 100644--- a/marimo/_ast/pytest.py+++ b/marimo/_ast/pytest.py@@ -6,6 +6,7 @@ import copyimport functoolsimport inspectimport itertools+from collections.abc import Awaitablefrom pathlib import Pathfrom typing import TYPE_CHECKING, Any, Callable, NoReturn, TypeVar, cast@@ -13,7 +14,7 @@ from marimo._ast.cell import Cellfrom marimo._runtime.context import ContextNotInitializedError, get_contextif TYPE_CHECKING:- from collections.abc import Awaitable, Mapping+ from collections.abc import MappingFn = TypeVar("Fn", bound=Callable[..., Any])@@ -167,7 +168,14 @@ def build_test_class(def hook(var: str) -> Callable[..., Any] | type[MarimoTest]:def _hook(*args: Any, **kwargs: Any) -> Any:- _, defs = run() # type: ignore+ res = run()+ if isinstance(res, Awaitable):+ import asyncio++ loop = asyncio.new_event_loop()+ _, defs = loop.run_until_complete(res)+ else:+ _, defs = resreturn defs[var](*args, **kwargs)test = tests.get(var, None)diff --git a/tests/_ast/test_pytest.py b/tests/_ast/test_pytest.pyindex 89d3c7a84b..5b11fb513a 100644--- a/tests/_ast/test_pytest.py+++ b/tests/_ast/test_pytest.py@@ -1,14 +1,16 @@from __future__ import annotations-import pytest-import marimoapp = marimo.App()+with app.setup:+ import pytest++@app.cell-async def _(pytest, x, y, Z):+async def _(x, y, Z):@pytest.mark.xfail(reason=("To ensure this doesn't just eval."),raises=AssertionError,@@ -45,6 +47,7 @@ async def _(pytest, x, y, Z):def test_static() -> None:assert x + y == Z+ @pytest.mark.asyncioasync def test_async_cell():assert True@@ -56,9 +59,7 @@ def imports():# Suffixed with _fixture should have corresponding definitions in conftest.pymo_fixture = None- import pytest-- return mo, mo_fixture, pytest+ return mo, mo_fixture@app.cell@@ -66,11 +67,18 @@ def test_cell_is_invoked():assert True@app.cellasync def test_async_cell():assert True+async def test_async_function():+ assert True++@app.functiondef test_top_level_function():assert True@@ -143,7 +151,7 @@ def test_cell_args_resolved_by_name(mo): # noqa: ARG001@app.cell-def test_cell_assert_rewritten(pytest):+def test_cell_assert_rewritten():a = 1b = 2