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: add rule to prevent test files from having the same name (#9671)
Dylan Madisetti3dd695500ba1
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex 1179bcabd5..332e5b21de 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -62,3 +62,12 @@ repos:args: [--write, --config, .oxfmtrc.json]files: ^(frontend/src/|packages/)"types_or": [javascript, jsx, ts, tsx]++ - repo: local+ hooks:+ - id: unique-test-filenames+ name: Enforce unique test filenames+ entry: python scripts/check_test_filenames.py+ language: system+ pass_filenames: false+ files: ^tests/.*\.py$diff --git a/scripts/check_test_filenames.py b/scripts/check_test_filenames.pynew file mode 100755index 0000000000..676e94b5a4--- /dev/null+++ b/scripts/check_test_filenames.py@@ -0,0 +1,69 @@+#!/usr/bin/env python3+# Copyright 2026 Marimo. All rights reserved.+"""Enforce unique basenames across `tests/`.++pytest's default `prepend` import mode imports collected test files as+top-level modules. When two files share a basename, the second import+clobbers the first and pytest fails collection with an error like:++ imported module 'test_exceptions' has this __file__ attribute:+ .../tests/_mcp/server/test_exceptions.py+ which is not the same as the test file we want to collect:+ .../tests/_runtime/test_exceptions.py++This script walks `tests/` and fails if any basename appears more than+once. Paths matched by pytest's `--ignore` list in pyproject.toml are+skipped (they hold fixture modules imported by name, not real tests).+"""++from __future__ import annotations++import sys+from collections import defaultdict+from pathlib import Path++REPO_ROOT = Path(__file__).resolve().parent.parent+TESTS_ROOT = REPO_ROOT / "tests"++# Mirror of `--ignore ...` entries in `[tool.pytest.ini_options].addopts`+# in pyproject.toml. Keep in sync if that list changes.+IGNORED_PREFIXES = (+ REPO_ROOT / "tests" / "_cli" / "fixtures",+ REPO_ROOT / "tests" / "_ast" / "codegen_data",+ REPO_ROOT / "tests" / "_ast" / "app_data",+)+++def is_ignored(path: Path) -> bool:+ return any(+ prefix in path.parents or path == prefix+ for prefix in IGNORED_PREFIXES+ )+++def main() -> int:+ by_name: dict[str, list[Path]] = defaultdict(list)+ for path in TESTS_ROOT.rglob("test_*.py"):+ if is_ignored(path):+ continue+ by_name[path.name].append(path)++ duplicates = {n: ps for n, ps in by_name.items() if len(ps) > 1}+ if not duplicates:+ return 0++ print("Duplicate test filenames found in tests/:", file=sys.stderr)+ print(+ "(pytest's default import mode requires unique basenames; "+ "rename one of each pair below)",+ file=sys.stderr,+ )+ for name in sorted(duplicates):+ print(f"\n {name}", file=sys.stderr)+ for path in sorted(duplicates[name]):+ print(f" {path.relative_to(REPO_ROOT)}", file=sys.stderr)+ return 1+++if __name__ == "__main__":+ sys.exit(main())diff --git a/tests/_code_mode/test_context.py b/tests/_code_mode/test_code_mode_context.pysimilarity index 100%rename from tests/_code_mode/test_context.pyrename to tests/_code_mode/test_code_mode_context.pydiff --git a/tests/_session/managers/test_app_host.py b/tests/_session/managers/test_app_host_kernel_manager.pysimilarity index 100%rename from tests/_session/managers/test_app_host.pyrename to tests/_session/managers/test_app_host_kernel_manager.pydiff --git a/tests/_session/notebook/test_loader.py b/tests/_session/notebook/test_app_file_manager.pysimilarity index 100%rename from tests/_session/notebook/test_loader.pyrename to tests/_session/notebook/test_app_file_manager.pydiff --git a/tests/_session/notebook/test_storage.py b/tests/_session/notebook/test_filesystem_storage.pysimilarity index 100%rename from tests/_session/notebook/test_storage.pyrename to tests/_session/notebook/test_filesystem_storage.py