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.

test(cli): poll for output file in export --watch tests to fix fs race (#10095)

Myles Scolnickbf6e16c82784
diff --git a/tests/_cli/test_cli_export.py b/tests/_cli/test_cli_export.py
index afa853bee7..5fbca32791 100644
--- a/tests/_cli/test_cli_export.py
+++ b/tests/_cli/test_cli_export.py
@@ -129,6 +129,23 @@ def _normalize_html_path(html: str, temp_file: str) -> str:
return html.replace(dirname, "path")
+async def _wait_for_file(file: str, timeout: float = 10.0) -> None:
+ """Poll until `file` exists, up to `timeout` seconds.
+
+ Logging "Re-exporting" and finishing the write to disk are separate
+ steps, so a fixed sleep between them is a race on slow CI runners.
+ Poll instead of assuming the write has landed.
+ """
+ deadline = time.time() + timeout
+ while time.time() < deadline:
+ if await async_path.exists(file):
+ return
+ await asyncio.sleep(0.05)
+ assert await async_path.exists(file), (
+ f"{file} was not created within {timeout}s"
+ )
+
+
class TestExportHTML:
@staticmethod
def test_cli_export_html(temp_marimo_file: str) -> None:
@@ -650,8 +667,7 @@ class TestExportScript:
assert "Re-exporting" in line
break
- await asyncio.sleep(0.1)
- assert await async_path.exists(temp_out_file)
+ await _wait_for_file(temp_out_file)
@pytest.mark.skipif(
condition=DependencyManager.watchdog.has(),
@@ -826,8 +842,7 @@ class TestExportMarkdown:
assert "Re-exporting" in line
break
- await asyncio.sleep(0.1)
- assert await async_path.exists(temp_out_file)
+ await _wait_for_file(temp_out_file)
@pytest.mark.skipif(
condition=DependencyManager.watchdog.has(),