Skip to content

Commit a903f3c

Browse files
selective cell exec
1 parent 64c797a commit a903f3c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

testing/test_notebooks.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,21 @@ def test_notebook_execution(notebook_path):
3030

3131
# Check if metadata is updated correctly
3232
print("Injected Metadata:", nb.metadata.get('parameters'))
33-
33+
34+
exec_globals = {}
3435
for idx, cell in enumerate(nb.cells):
35-
print(f"Cell {idx} Type: {cell['cell_type']}")
36-
print(cell['source'][:100]) # Print the first 100 characters of the cell source
36+
if cell.cell_type == "code":
37+
print(f"Executing Cell {idx}:")
38+
print(cell['source'][:100]) # Print the first 100 characters of the cell source
39+
try:
40+
exec(cell.source, exec_globals)
41+
except Exception as e:
42+
print(f"Error in Cell {idx}: {e}")
43+
44+
45+
#for idx, cell in enumerate(nb.cells):
46+
# print(f"Cell {idx} Type: {cell['cell_type']}")
47+
# print(cell['source'][:100]) # Print the first 100 characters of the cell source
3748

3849
#ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
3950
#ep.preprocess(nb, {'metadata': {'path': './'}})

0 commit comments

Comments
 (0)