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.

chore: add a script to make running Python tests more convenient (#8417)

Akshay Agrawalbf062c2dcb41
diff --git a/Makefile b/Makefile
index bf6310d038..af4c6d2426 100644
--- a/Makefile
+++ b/Makefile
@@ -123,8 +123,8 @@ typos:
.PHONY: py-test
# 🧪 Test python
py-test:
- @command -v hatch >/dev/null 2>&1 || { echo "hatch is required. See https://hatch.pypa.io/dev/install/"; exit 1; }
- hatch run typos && hatch run +py=3.12 test-optional:test $(ARGS)
+ uvx hatch run typos
+ ./scripts/pytest.sh --optional $(ARGS)
.PHONY: py-snapshots
# 📸 Update snapshots
diff --git a/scripts/pytest.sh b/scripts/pytest.sh
new file mode 100755
index 0000000000..cb62eb3402
--- /dev/null
+++ b/scripts/pytest.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+set -e
+
+usage() {
+ echo "Usage: $0 [--py VERSION] [--optional] [-- PYTEST_ARGS...]"
+ echo ""
+ echo "Options:"
+ echo " --py VERSION Python version (e.g. 3.12). Default: 3.12"
+ echo " --optional Use test-optional env (includes optional deps)"
+ echo ""
+ echo "Everything after -- is forwarded to pytest."
+ echo "If no -- is used, all unrecognized args are forwarded to pytest."
+ echo ""
+ echo "Examples:"
+ echo " $0 tests/_runtime/test_threads.py"
+ echo " $0 --py 3.11 --optional tests/_runtime/test_threads.py -v"
+ echo " $0 --py 3.13 -- tests/ -k 'test_foo' -x"
+ exit 1
+}
+
+PY_VERSION="3.12"
+ENV="test"
+
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --py)
+ PY_VERSION="$2"
+ shift 2
+ ;;
+ --optional)
+ ENV="test-optional"
+ shift
+ ;;
+ -h|--help)
+ usage
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ break
+ ;;
+ esac
+done
+
+exec uvx hatch run +py="$PY_VERSION" "$ENV:test" "$@"