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.

fix: pytest failed in wasm due to not setting env variables in pyodid… (#4476)

Dylan Madisetti7049cb8e2990
diff --git a/marimo/_ast/cell.py b/marimo/_ast/cell.py
index 09f24ab86c..bfc5758848 100644
--- a/marimo/_ast/cell.py
+++ b/marimo/_ast/cell.py
@@ -638,7 +638,10 @@ class Cell:
f"{self.name}() got an unexpected argument(s) '{unexpected}'"
)
- is_pytest = "PYTEST_CURRENT_TEST" in os.environ
+ is_pytest = (
+ "PYTEST_CURRENT_TEST" in os.environ
+ or "MARIMO_PYTEST_WASM" in os.environ
+ )
# Capture pytest case, where arguments don't match the references.
if self._pytest_reserved - set(arg_names):
raise TypeError(
diff --git a/marimo/_ast/cell_manager.py b/marimo/_ast/cell_manager.py
index 4b3b21dfca..a3648ecd9e 100644
--- a/marimo/_ast/cell_manager.py
+++ b/marimo/_ast/cell_manager.py
@@ -108,7 +108,7 @@ class CellManager:
is_top_level_pytest = (
"PYTEST_VERSION" in os.environ
and "PYTEST_CURRENT_TEST" not in os.environ
- )
+ ) or "MARIMO_PYTEST_WASM" in os.environ
factory: Callable[..., Cell] = (
toplevel_cell_factory if top_level else cell_factory
)
diff --git a/marimo/_runtime/pytest.py b/marimo/_runtime/pytest.py
index 0d1bdf852e..3a891da9d3 100644
--- a/marimo/_runtime/pytest.py
+++ b/marimo/_runtime/pytest.py
@@ -268,6 +268,9 @@ def run_pytest(
# the normal behavior (in which pytest alters the system path).
plugin = ReplaceStubPlugin(defs, lcls)
try:
+ # pytest in wasm doesn't seem to set environment variables correctly.
+ # This work around is to prevent collision with non-wasm testing.
+ os.environ["MARIMO_PYTEST_WASM"] = "1"
with capture_stdout() as stdout:
pytest.main(
[
@@ -280,6 +283,7 @@ def run_pytest(
plugins=[plugin],
)
finally:
+ del os.environ["MARIMO_PYTEST_WASM"]
# Note, in pytester, there are also exceptions for zope and readline.
# However, those deps should already be in module_snapshot, since
# dependencies are required before the given cell runs.