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
tests: upgrade pytest plugins, upperbound sqlglot (#8077)
Myles Scolnick7dbe4b5790ba
diff --git a/marimo/_ast/pytest.py b/marimo/_ast/pytest.pyindex dfd82eb324..e8ee5d8e65 100644--- a/marimo/_ast/pytest.py+++ b/marimo/_ast/pytest.py@@ -224,23 +224,43 @@ def _make_hook(| Awaitable[tuple[Any, Mapping[str, Any]]],],use_wrapped: bool = False,+ is_async: bool = False,) -> Callable[..., Any]:"""Single hook factory - handles both fixtures and tests."""- def _hook(*args: Any, **kwargs: Any) -> Any:- res = run()- if isinstance(res, Awaitable):- import asyncio+ if is_async:- loop = asyncio.new_event_loop()- _, cell_defs = loop.run_until_complete(res)- else:- _, cell_defs = res+ async def _async_hook(*args: Any, **kwargs: Any) -> Any:+ res = run()+ if isinstance(res, Awaitable):+ _, cell_defs = await res+ else:+ _, cell_defs = res++ target = (+ cell_defs[var].__wrapped__ if use_wrapped else cell_defs[var]+ )+ return await target(*args, **kwargs)++ return _async_hook+ else:++ def _hook(*args: Any, **kwargs: Any) -> Any:+ res = run()+ if isinstance(res, Awaitable):+ import asyncio- target = cell_defs[var].__wrapped__ if use_wrapped else cell_defs[var]- return target(*args, **kwargs)+ loop = asyncio.new_event_loop()+ _, cell_defs = loop.run_until_complete(res)+ else:+ _, cell_defs = res++ target = (+ cell_defs[var].__wrapped__ if use_wrapped else cell_defs[var]+ )+ return target(*args, **kwargs)- return _hook+ return _hookdef _build_hook(@@ -252,7 +272,8 @@ def _build_hook(is_fixture: bool = False,) -> Callable[..., Any]:"""Build hook for test or fixture function."""- hook = _make_hook(var, run, use_wrapped=is_fixture)+ is_async = isinstance(test, ast.AsyncFunctionDef)+ hook = _make_hook(var, run, use_wrapped=is_fixture, is_async=is_async)stub_fn = build_stub_fn(test, file)functools.wraps(stub_fn)(hook)diff --git a/marimo/_runtime/pytest.py b/marimo/_runtime/pytest.pyindex fc402cfb79..1a29978fb4 100644--- a/marimo/_runtime/pytest.py+++ b/marimo/_runtime/pytest.py@@ -352,6 +352,10 @@ def run_pytest("--disable-warnings","--color=yes","--code-highlight=no",+ "-p",+ "no:codecov", # Disable codecov plugin to avoid duplicate reports+ "-p",+ "no:sugar", # Disable sugar plugin to avoid duplicate reportsnotebook_path,],plugins=[plugin],diff --git a/packages/pytest_changed/__init__.py b/packages/pytest_changed/__init__.pyindex 50e98e107c..d829e827f5 100644--- a/packages/pytest_changed/__init__.py+++ b/packages/pytest_changed/__init__.py@@ -8,6 +8,8 @@ Usage:pytest --changed-from=origin/main"""+from __future__ import annotations+import jsonimport subprocessfrom pathlib import Path@@ -17,6 +19,10 @@ import pytestprint_ = print+class UnreachableError(Exception):+ pass++def pytest_addoption(parser: pytest.Parser) -> None:"""Add command-line options for the plugin."""group = parser.getgroup(@@ -39,7 +45,7 @@ def pytest_addoption(parser: pytest.Parser) -> None:)-def get_changed_files(ref: str, repo_root: Path) -> set[Path]:+def get_changed_files(ref: str, repo_root: Path) -> tuple[set[Path], bool]:"""Get list of changed Python files from git diff.@@ -48,8 +54,12 @@ def get_changed_files(ref: str, repo_root: Path) -> set[Path]:repo_root: Root of the git repositoryReturns:- Set of absolute paths to changed Python files+ Tuple of (set of changed Python files, bool indicating if critical files changed)+ Critical files are configuration files that affect all tests (e.g., pyproject.toml)"""+ # Files that, if changed, should trigger all tests+ critical_files = {"pyproject.toml"}+try:result = subprocess.run(["git", "diff", "--name-only", ref],@@ -60,14 +70,21 @@ def get_changed_files(ref: str, repo_root: Path) -> set[Path]:)changed_files: set[Path] = set()+ critical_changed = False+for line in result.stdout.strip().split("\n"):if not line:continuefile_path = repo_root / line++ # Check for critical configuration files+ if file_path.name in critical_files:+ critical_changed = True+if file_path.suffix == ".py" and file_path.exists():changed_files.add(file_path)- return changed_files+ return changed_files, critical_changedexcept subprocess.CalledProcessError as e:error_msg = f"Failed to get git diff from '{ref}': {e}"if e.stderr:@@ -129,6 +146,8 @@ def get_dependency_graph(except json.JSONDecodeError as e:pytest.exit(f"Failed to parse ruff output: {e}", returncode=1)+ raise UnreachableError("Failed to run ruff analyze graph")+def find_affected_files(changed_files: set[Path],@@ -220,6 +239,7 @@ def pytest_configure(config: pytest.Config) -> None:return# Get the repository root+ repo_root: Pathtry:result = subprocess.run(["git", "rev-parse", "--show-toplevel"],@@ -228,14 +248,26 @@ def pytest_configure(config: pytest.Config) -> None:check=True,)repo_root = Path(result.stdout.strip())- except subprocess.CalledProcessError:+ except subprocess.CalledProcessError as e:pytest.exit("Not in a git repository", returncode=1)+ raise UnreachableError("Not in a git repository") from e# Get test base directory from args or fall back to repo roottest_base = get_test_base(config, repo_root)# Step 1: Find changed files- changed_files = get_changed_files(changed_from, repo_root)+ changed_files, critical_changed = get_changed_files(+ changed_from, repo_root+ )++ # If critical files changed, run all tests+ if critical_changed:+ print_(+ "\nCritical configuration files changed (e.g., pyproject.toml) - "+ "running all tests"+ )+ config.option.changed_test_files = None # None means run all tests+ returnif not changed_files:print_(f"No Python files changed from {changed_from}")@@ -290,10 +322,15 @@ def pytest_collection_modifyitems(if changed_from is None:return- changed_test_files: set[Path] = getattr(+ changed_test_files: set[Path] | None = getattr(config.option, "changed_test_files", set())+ # None means run all tests (critical files changed)+ if changed_test_files is None:+ print_(f"\nRunning all {len(items)} tests")+ return+if not changed_test_files:# No affected tests, skip allfor item in items:diff --git a/pyproject.toml b/pyproject.tomlindex 6f5c960957..95d45d7613 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -84,7 +84,7 @@ marimo_converter = "marimo._utils.docs:MarimoConverter"sql = ["duckdb>=1.0.0", # SQL cells"polars[pyarrow]>=1.9.0", # SQL output back in Python- "sqlglot[rs]>=26.2.0" # SQL cells parsing+ "sqlglot[rs]>=26.2.0,<28.7.0" # SQL cells parsing; <28.7.0 due to ibis compatibility issue]# For per-notebook sandboxed kernels@@ -137,13 +137,13 @@ test = ["httpx~=0.28.0","urllib3~=2.5.0",# Pytest and plugins- "pytest~=8.3.4",- "pytest-timeout~=2.3.1",+ "pytest~=9.0.2",+ "pytest-timeout~=2.4.0","pytest-codecov~=0.7.0",- "pytest-rerunfailures~=15.1",- "pytest-asyncio~=0.26.0",+ "pytest-rerunfailures~=16.1",+ "pytest-asyncio~=1.3.0","pytest-picked>=0.5.1",- "pytest-sugar~=1.0.0",+ "pytest-sugar~=1.1.1",# Comparison testing"inline-snapshot~=0.29.0","hypothesis~=6.102.1",@@ -168,7 +168,7 @@ test-optional = ["altair>=5.4.0","plotly>=5.14.0","polars>=1.32.2",- "sqlglot[rs]>=26.2.0",+ "sqlglot[rs]>=26.2.0,<28.7.0", # <28.7.0 due to ibis compatibility issue"sqlalchemy>=2.0.40","pyiceberg>=0.9.0","cloudpathlib>=0.23.0",diff --git a/tests/_runtime/test_pytest_runtime.py b/tests/_runtime/test_pytest_runtime.pyindex d9562d91a1..daffdb907f 100644--- a/tests/_runtime/test_pytest_runtime.py+++ b/tests/_runtime/test_pytest_runtime.py@@ -1,8 +1,14 @@+from __future__ import annotations+import asyncioimport os+import sysfrom pathlib import Path+import pytest+[email protected](sys.platform == "win32", reason="Fails on Windows CI")def test_smoke_test():from marimo._runtime.pytest import run_pytestfrom tests._runtime.script_data.contains_tests import appdiff --git a/tests/conftest.py b/tests/conftest.pyindex 327df6dd5c..f11d13fd80 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -40,6 +40,7 @@ from marimo._runtime.input_override import input_overridefrom marimo._runtime.marimo_pdb import MarimoPdbfrom marimo._runtime.runtime import Kernelfrom marimo._save.stubs.module_stub import ModuleStub+from marimo._server.utils import initialize_mimetypesfrom marimo._session.model import SessionModefrom marimo._types.ids import CellId_t@@ -50,6 +51,9 @@ if TYPE_CHECKING:# register import hooks for third-party module formattersregister_formatters()+# Initialize mimetypes for consistent behavior across platforms (especially Windows)+initialize_mimetypes()+def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]