Skip to content

Commit 58753a4

Browse files
committed
Lazy-import notebook test deps to fix conda-build collection
nest_asyncio is a dev-only dependency and not part of the conda runtime deps, so importing it at module level broke pytest collection in the conda-build pipeline. Move nbformat, nest_asyncio and ExecutePreprocessor imports into _run_notebook so collection no longer requires them. ✨ Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> 🍐
1 parent b80bd89 commit 58753a4

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

karabo/test/test_notebooks.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import os
22

3-
import nbformat
4-
import nest_asyncio
53
import pytest
6-
from nbconvert.preprocessors import ExecutePreprocessor
74

85
from karabo.test.conftest import IS_GITHUB_RUNNER
96
from karabo.util.plotting_util import Font
107

11-
nest_asyncio.apply()
12-
138
RUN_NOTEBOOK_TESTS = os.environ.get("RUN_NOTEBOOK_TESTS", "false").lower() == "true"
149

1510
# get notebook-dir not matter cwd
1611
notebook_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "examples")
1712

1813

1914
def _run_notebook(notebook: str) -> None:
15+
# Imported lazily: these are dev-only dependencies (see pyproject.toml) and
16+
# are not part of the conda runtime deps, so importing them at module level
17+
# would break test collection in the conda-build pipeline.
18+
import nbformat
19+
import nest_asyncio
20+
from nbconvert.preprocessors import ExecutePreprocessor
21+
22+
nest_asyncio.apply()
23+
2024
notebook = os.path.join(notebook_dir, notebook)
2125
print(Font.BOLD + Font.BLUE + "Testing notebook " + notebook + Font.END)
2226

0 commit comments

Comments
 (0)