Skip to content

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.

tests: add @pytest.mark.requires() markers (#7908)

Myles Scolnick52a592c33d3d
diff --git a/.vscode/settings.json b/.vscode/settings.json
index e119b2bc34..c785a277e9 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -25,6 +25,14 @@
"editor.defaultFormatter": "biomejs.biome",
},
+ "python.testing.pytestEnabled": true,
+ "python.testing.pytestArgs": [
+ "tests",
+ "-v",
+ "--tb=short"
+ ],
+ "python.testing.autoTestDiscoverOnSaveEnabled": true,
+
// Other settings that match our linters
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
diff --git a/pixi.lock b/pixi.lock
index 25740b47de..f61ae758d8 100644
--- a/pixi.lock
+++ b/pixi.lock
@@ -113,7 +113,7 @@ environments:
- pypi: https://files.pythonhosted.org/packages/04/96/92447566d16df59b2a776c0fb82dbc4d9e07cd95062562af01e408583fc4/itsdangerous-2.2.0-py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/c0/5a/9cac0c82afec3d09ccd97c8b6502d48f165f9124db81b4bcb90b4af974ee/jedi-0.19.2-py2.py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/b2/70/00dc4246d9f3c69ecbb9bc36d5ad1a359884464a44711c665cb0afb1e9de/loro-1.10.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- - pypi: https://files.pythonhosted.org/packages/70/81/54e3ce63502cd085a0c556652a4e1b919c45a446bd1e5300e10c44c8c521/markdown-3.10-py3-none-any.whl
+ - pypi: https://files.pythonhosted.org/packages/59/1b/6ef961f543593969d25b2afe57a3564200280528caa9bd1082eecdd7b3bc/markdown-3.10.1-py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/5c/a2/488517a43ccf5a4b6b6eca6dd4ede0bd82b043d1539dd6bb908a19f8efd3/msgspec-0.20.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- pypi: https://files.pythonhosted.org/packages/3d/2e/cf2ffeb386ac3763526151163ad7da9f1b586aac96d2b4f7de1eaebf0c61/narwhals-2.15.0-py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/16/32/f8e3c85d1d5250232a5d3477a2a28cc291968ff175caeadaf3cc19ce0e4a/parso-0.8.5-py2.py3-none-any.whl
@@ -211,7 +211,7 @@ environments:
- pypi: https://files.pythonhosted.org/packages/04/96/92447566d16df59b2a776c0fb82dbc4d9e07cd95062562af01e408583fc4/itsdangerous-2.2.0-py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/c0/5a/9cac0c82afec3d09ccd97c8b6502d48f165f9124db81b4bcb90b4af974ee/jedi-0.19.2-py2.py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/78/e4/7b614260bf16c5e33c0bea6ac47ab0284efd21f89f2e5e4e15cd93bead40/loro-1.10.3-cp312-cp312-macosx_11_0_arm64.whl
- - pypi: https://files.pythonhosted.org/packages/70/81/54e3ce63502cd085a0c556652a4e1b919c45a446bd1e5300e10c44c8c521/markdown-3.10-py3-none-any.whl
+ - pypi: https://files.pythonhosted.org/packages/59/1b/6ef961f543593969d25b2afe57a3564200280528caa9bd1082eecdd7b3bc/markdown-3.10.1-py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/7f/ee/af51d090ada641d4b264992a486435ba3ef5b5634bc27e6eb002f71cef7d/msgspec-0.20.0-cp312-cp312-macosx_11_0_arm64.whl
- pypi: https://files.pythonhosted.org/packages/3d/2e/cf2ffeb386ac3763526151163ad7da9f1b586aac96d2b4f7de1eaebf0c61/narwhals-2.15.0-py3-none-any.whl
- pypi: https://files.pythonhosted.org/packages/16/32/f8e3c85d1d5250232a5d3477a2a28cc291968ff175caeadaf3cc19ce0e4a/parso-0.8.5-py2.py3-none-any.whl
@@ -1133,7 +1133,7 @@ packages:
- pypi: ./
name: marimo
version: 0.19.4
- sha256: b8269f90d1490e837a501cbe0ef11c21a96842e7b52ad2430d0a5a9122bde661
+ sha256: 0f6da2ae122ccc9a0a8b91226e8605a8094365ed84ced7d470f1b70730a22140
requires_dist:
- click>=8.0,<9
- jedi>=0.18.0
@@ -1169,17 +1169,17 @@ packages:
- mcp>=1.0.0 ; extra == 'mcp'
- pydantic>2 ; extra == 'mcp'
requires_python: '>=3.10'
-- pypi: https://files.pythonhosted.org/packages/70/81/54e3ce63502cd085a0c556652a4e1b919c45a446bd1e5300e10c44c8c521/markdown-3.10-py3-none-any.whl
+- pypi: https://files.pythonhosted.org/packages/59/1b/6ef961f543593969d25b2afe57a3564200280528caa9bd1082eecdd7b3bc/markdown-3.10.1-py3-none-any.whl
name: markdown
- version: '3.10'
- sha256: b5b99d6951e2e4948d939255596523444c0e677c669700b1d17aa4a8a464cb7c
+ version: 3.10.1
+ sha256: 867d788939fe33e4b736426f5b9f651ad0c0ae0ecf89df0ca5d1176c70812fe3
requires_dist:
- coverage ; extra == 'testing'
- pyyaml ; extra == 'testing'
- mkdocs>=1.6 ; extra == 'docs'
- mkdocs-nature>=0.6 ; extra == 'docs'
- mdx-gh-links>=0.2 ; extra == 'docs'
- - mkdocstrings[python] ; extra == 'docs'
+ - mkdocstrings[python]>=0.28.3 ; extra == 'docs'
- mkdocs-gen-files ; extra == 'docs'
- mkdocs-section-index ; extra == 'docs'
- mkdocs-literate-nav ; extra == 'docs'
diff --git a/pyproject.toml b/pyproject.toml
index 45fc26cd99..89abd4f473 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -143,6 +143,7 @@ test = [
"pytest-rerunfailures~=15.1",
"pytest-asyncio~=0.26.0",
"pytest-picked>=0.5.1",
+ "pytest-sugar~=1.0.0",
# Comparison testing
"inline-snapshot~=0.29.0",
"hypothesis~=6.102.1",
@@ -517,6 +518,13 @@ asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
timeout = 30 # seconds, per test
faulthandler_timeout = 30 # seconds, during collection
+markers = [
+ "slow: marks tests as slow (deselect with '-m \"not slow\"')",
+ "integration: marks tests as integration tests",
+ "unit: marks tests as unit tests",
+ "flaky: marks tests that are known to be flaky",
+ "requires(dep1, dep2, ...): requires one or more dependencies to be installed",
+]
[tool.coverage.run]
omit = ["marimo/_tutorials/*"]
diff --git a/tests/_sql/test_engines.py b/tests/_sql/test_engines.py
index 082e6db723..48550213bb 100644
--- a/tests/_sql/test_engines.py
+++ b/tests/_sql/test_engines.py
@@ -25,10 +25,7 @@ HAS_POLARS = DependencyManager.polars.has()
UNUSED_DB_NAME = "unused_db"
- not HAS_DUCKDB or not HAS_SQLALCHEMY or not HAS_PANDAS,
- reason="Duckdb, sqlalchemy and pandas not installed",
-)
[email protected]("duckdb", "sqlalchemy", "pandas")
def test_engine_compatibility() -> None:
"""Test engine compatibility checks."""
import duckdb
@@ -49,10 +46,7 @@ def test_raise_df_import_error() -> None:
raise_df_import_error("test_pkg")
- not (HAS_DUCKDB and HAS_SQLALCHEMY),
- reason="Duckdb, sqlalchemy, and Clickhouse not installed",
-)
[email protected]("duckdb", "sqlalchemy")
def test_engine_name_initialization() -> None:
"""Test engine name initialization."""
import duckdb
@@ -77,7 +71,7 @@ def test_engine_name_initialization() -> None:
duckdb_conn.close()
[email protected](not HAS_CLICKHOUSE, reason="Clickhouse not installed")
@pytest.mark.skip("chdb is flakey")
def test_clickhouse_engine_name_initialization() -> None:
"""Test ClickhouseEngine engine name initialization."""
@@ -92,7 +86,7 @@ def test_clickhouse_engine_name_initialization() -> None:
clickhouse_conn.close()
[email protected](not HAS_DUCKDB, reason="Duckdb not installed")
def test_duckdb_source_and_dialect() -> None:
"""Test DuckDBEngine source and dialect properties."""
import duckdb
@@ -106,7 +100,7 @@ def test_duckdb_source_and_dialect() -> None:
duckdb_conn.close()
[email protected](not HAS_SQLALCHEMY, reason="SQLAlchemy not installed")
[email protected]("sqlalchemy")
def test_sqlalchemy_source_and_dialect() -> None:
"""Test SQLAlchemyEngine source and dialect properties."""
import sqlalchemy as sa
@@ -127,7 +121,7 @@ def test_sqlalchemy_source_and_dialect() -> None:
assert pg_engine.dialect == "postgresql"
[email protected](not HAS_DUCKDB, reason="Duckdb not installed")
def test_duckdb_get_current_database_and_schema() -> None:
"""Test DuckDBEngine get_current_database and get_current_schema methods."""
import duckdb
@@ -146,7 +140,7 @@ def test_duckdb_get_current_database_and_schema() -> None:
# Connection already closed, no need to close again
[email protected](not HAS_SQLALCHEMY, reason="SQLAlchemy not installed")
[email protected]("sqlalchemy")
def test_sqlalchemy_get_databases() -> None:
"""Test SQLAlchemyEngine get_databases method."""
import sqlalchemy as sa
@@ -204,7 +198,7 @@ def test_sqlalchemy_get_databases() -> None:
) # SQLite is cheap discovery
[email protected](not HAS_SQLALCHEMY, reason="SQLAlchemy not installed")
[email protected]("sqlalchemy")
def test_sqlalchemy_get_table_details() -> None:
"""Test SQLAlchemyEngine get_table_details method."""
import sqlalchemy as sa
@@ -245,10 +239,7 @@ def test_sqlalchemy_get_table_details() -> None:
assert "name" in column_names
- not HAS_DUCKDB or not (HAS_PANDAS or HAS_POLARS),
- reason="Duckdb and either pandas or polars not installed",
-)
[email protected]("duckdb", "pandas", "polars")
def test_duckdb_execute() -> None:
"""Test DuckDBEngine execute method."""
import duckdb
@@ -279,10 +270,7 @@ def test_duckdb_execute() -> None:
duckdb_conn.close()
- not HAS_DUCKDB or not HAS_POLARS,
- reason="Duckdb and polars not installed",
-)
[email protected]("duckdb", "polars")
def test_duckdb_execute_in_explain_mode():
"""Test DuckDBEngine execute in explain mode."""
import duckdb
@@ -330,10 +318,7 @@ def test_duckdb_execute_in_explain_mode():
duckdb_conn.close()
- not HAS_SQLALCHEMY or not (HAS_PANDAS or HAS_POLARS),
- reason="SQLAlchemy and either pandas or polars not installed",
-)
[email protected]("sqlalchemy", "pandas", "polars")
class TestExecuteExplainModeSQLAlchemy:
@pytest.fixture
def engine(self) -> SQLAlchemyEngine:
@@ -366,7 +351,7 @@ class TestExecuteExplainModeSQLAlchemy:
assert engine.execute("PRAGMA journal_mode=WAL") is not None
[email protected](not HAS_SQLALCHEMY, reason="SQLAlchemy not installed")
[email protected]("sqlalchemy")
def test_sqlalchemy_execute_in_explain_mode():
"""Test SQLAlchemyEngine execute in explain mode."""
import sqlalchemy as sa
@@ -438,7 +423,7 @@ def test_sql_type_to_data_type() -> None:
assert sql_type_to_data_type("UNKNOWN_TYPE") == "string"
[email protected](not HAS_SQLALCHEMY, reason="SQLAlchemy not installed")
[email protected]("sqlalchemy")
def test_sqlalchemy_type_conversion() -> None:
"""Test SQLAlchemyEngine _get_python_type and _get_generic_type methods."""
import sqlalchemy as sa
@@ -465,10 +450,7 @@ def test_sqlalchemy_type_conversion() -> None:
assert engine._get_python_type(CustomType()) is None
- not HAS_POLARS and not HAS_SQLALCHEMY,
- reason="Polars and SQLAlchemy not installed",
-)
[email protected]("polars", "sqlalchemy")
def test_try_convert_to_polars() -> None:
"""Test try_convert_to_polars function."""
import polars as pl
diff --git a/tests/conftest.py b/tests/conftest.py
index 04271ff497..327df6dd5c 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -16,6 +16,7 @@ from marimo._ast.app import App
from marimo._ast.app_config import _AppConfig
from marimo._ast.cell_manager import CellManager
from marimo._config.config import DEFAULT_CONFIG
+from marimo._dependencies.dependencies import DependencyManager
from marimo._messaging.mimetypes import ConsoleMimeType
from marimo._messaging.notification import (
CellNotification,
@@ -50,6 +51,35 @@ if TYPE_CHECKING:
register_formatters()
+def pytest_collection_modifyitems(
+ config: pytest.Config, items: list[pytest.Item]
+) -> None:
+ """Auto-skip tests based on @pytest.mark.requires() markers."""
+ del config # Unused but required by pytest hook signature
+ for item in items:
+ requires_marker = item.get_closest_marker("requires")
+ if not requires_marker:
+ continue
+
+ missing_deps = []
+ # Get dependency names from marker args
+ for dep_name in requires_marker.args:
+ # Try to get the dependency from DependencyManager
+ dep_manager = getattr(DependencyManager, dep_name, None)
+ if dep_manager is not None:
+ if not dep_manager.has():
+ missing_deps.append(dep_name)
+ else:
+ # Unknown dependency name
+ missing_deps.append(f"{dep_name} (unknown)")
+
+ # Skip test if any dependencies are missing
+ if missing_deps:
+ deps_str = ", ".join(missing_deps)
+ reason = f"requires {deps_str}"
+ item.add_marker(pytest.mark.skip(reason=reason))
+
+
@pytest.fixture(autouse=True)
def patch_random_seed(monkeypatch: pytest.MonkeyPatch) -> None:
"""Patch UIElement._random_seed to use a fixed seed for testing"""