|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": { |
| 6 | + "application/vnd.databricks.v1+cell": { |
| 7 | + "cellMetadata": {}, |
| 8 | + "inputWidgets": {}, |
| 9 | + "nuid": "92d99175-d1dd-4306-a3ef-3ebe461105fc", |
| 10 | + "showTitle": true, |
| 11 | + "tableResultSettingsMap": {}, |
| 12 | + "title": "Tablespec Integration Tests on Databricks" |
| 13 | + } |
| 14 | + }, |
| 15 | + "source": [ |
| 16 | + "# Tablespec Integration Tests on Databricks\n", |
| 17 | + "\n", |
| 18 | + "Runs the test suite **in-process** using `ipytest` for notebook-friendly output.\n", |
| 19 | + "\n", |
| 20 | + "Key design decisions:\n", |
| 21 | + "- **`%pip install -e`** (magic, not subprocess) — triggers interpreter restart so `.pth`\n", |
| 22 | + " files are processed and `import tablespec` just works. No `sys.path` hacking.\n", |
| 23 | + "- **`ipytest`** — thin pytest wrapper that renders results inline in the notebook.\n", |
| 24 | + "- **In-process execution** — critical so the `spark_session` fixture can pick up the\n", |
| 25 | + " runtime's active SparkSession via `create_delta_spark_session() → getActiveSession()`.\n", |
| 26 | + " A subprocess cannot access the Databricks Spark Connect session.\n", |
| 27 | + "\n", |
| 28 | + "**Requirements:** Attach to any Databricks cluster or use serverless compute." |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "code", |
| 33 | + "execution_count": 0, |
| 34 | + "metadata": { |
| 35 | + "application/vnd.databricks.v1+cell": { |
| 36 | + "cellMetadata": {}, |
| 37 | + "inputWidgets": {}, |
| 38 | + "nuid": "9b1d3763-3dc6-4d9e-b2a6-2eb46710f1f1", |
| 39 | + "showTitle": true, |
| 40 | + "tableResultSettingsMap": {}, |
| 41 | + "title": "Install tablespec + test dependencies" |
| 42 | + } |
| 43 | + }, |
| 44 | + "outputs": [], |
| 45 | + "source": [ |
| 46 | + "# %pip triggers an interpreter restart, so .pth files from editable installs\n", |
| 47 | + "# are processed automatically — no sys.path manipulation needed.\n", |
| 48 | + "%pip install -e /Workspace/Users/erik.labianca@synaptiq.ai/tablespec --quiet\n", |
| 49 | + "%pip install ipytest pytest-cov pytest-mock anyio hypothesis --quiet" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": 0, |
| 55 | + "metadata": { |
| 56 | + "application/vnd.databricks.v1+cell": { |
| 57 | + "cellMetadata": {}, |
| 58 | + "inputWidgets": {}, |
| 59 | + "nuid": "34b3889f-cc9d-478d-b751-6d81ab3c97d4", |
| 60 | + "showTitle": true, |
| 61 | + "tableResultSettingsMap": {}, |
| 62 | + "title": "Configure ipytest" |
| 63 | + } |
| 64 | + }, |
| 65 | + "outputs": [], |
| 66 | + "source": [ |
| 67 | + "import ipytest\n", |
| 68 | + "import os\n", |
| 69 | + "import sys\n", |
| 70 | + "\n", |
| 71 | + "PROJECT_ROOT = \"/Workspace/Users/erik.labianca@synaptiq.ai/tablespec\"\n", |
| 72 | + "\n", |
| 73 | + "# Disable bytecode caching (workspace FS doesn't support __pycache__)\n", |
| 74 | + "os.environ[\"PYTHONDONTWRITEBYTECODE\"] = \"1\"\n", |
| 75 | + "sys.dont_write_bytecode = True\n", |
| 76 | + "\n", |
| 77 | + "# Configure ipytest: notebook-friendly output, raises on failure\n", |
| 78 | + "ipytest.autoconfig(\n", |
| 79 | + " addopts=[\"-v\", \"--tb=short\", \"-p\", \"no:cacheprovider\"],\n", |
| 80 | + " run_in_thread=False,\n", |
| 81 | + " raise_on_error=True,\n", |
| 82 | + ")" |
| 83 | + ] |
| 84 | + }, |
| 85 | + { |
| 86 | + "cell_type": "code", |
| 87 | + "execution_count": 0, |
| 88 | + "metadata": { |
| 89 | + "application/vnd.databricks.v1+cell": { |
| 90 | + "cellMetadata": {}, |
| 91 | + "inputWidgets": {}, |
| 92 | + "nuid": "453f0af0-c2ff-4e04-9d51-973f5687171c", |
| 93 | + "showTitle": true, |
| 94 | + "tableResultSettingsMap": {}, |
| 95 | + "title": "Run integration tests" |
| 96 | + } |
| 97 | + }, |
| 98 | + "outputs": [], |
| 99 | + "source": [ |
| 100 | + "ipytest.run(os.path.join(PROJECT_ROOT, \"tests/integration/\"))" |
| 101 | + ] |
| 102 | + }, |
| 103 | + { |
| 104 | + "cell_type": "code", |
| 105 | + "execution_count": 0, |
| 106 | + "metadata": { |
| 107 | + "application/vnd.databricks.v1+cell": { |
| 108 | + "cellMetadata": {}, |
| 109 | + "inputWidgets": {}, |
| 110 | + "nuid": "32881786-30cc-4510-a191-f097dccc5fb9", |
| 111 | + "showTitle": true, |
| 112 | + "tableResultSettingsMap": {}, |
| 113 | + "title": "Run full test suite" |
| 114 | + } |
| 115 | + }, |
| 116 | + "outputs": [], |
| 117 | + "source": [ |
| 118 | + "# Full suite: unit + integration (skips modules needing local-only spark setup)\n", |
| 119 | + "ipytest.run(\n", |
| 120 | + " os.path.join(PROJECT_ROOT, \"tests/\"),\n", |
| 121 | + " \"--ignore=tests/unit/test_quality_executor_selection.py\",\n", |
| 122 | + " \"--ignore=tests/unit/test_baseline_service.py\",\n", |
| 123 | + ")" |
| 124 | + ] |
| 125 | + } |
| 126 | + ], |
| 127 | + "metadata": { |
| 128 | + "application/vnd.databricks.v1+notebook": { |
| 129 | + "computePreferences": null, |
| 130 | + "dashboards": [], |
| 131 | + "environmentMetadata": null, |
| 132 | + "inputWidgetPreferences": null, |
| 133 | + "language": "python", |
| 134 | + "notebookMetadata": {}, |
| 135 | + "notebookName": "run_integration_tests_databricks", |
| 136 | + "widgets": {} |
| 137 | + }, |
| 138 | + "kernelspec": { |
| 139 | + "display_name": "Python 3", |
| 140 | + "language": "python", |
| 141 | + "name": "python3" |
| 142 | + }, |
| 143 | + "language_info": { |
| 144 | + "name": "python" |
| 145 | + } |
| 146 | + }, |
| 147 | + "nbformat": 4, |
| 148 | + "nbformat_minor": 0 |
| 149 | +} |
0 commit comments