jtpio / ipylab

Control JupyterLab from Python Notebooks with Jupyter Widgets 🧪 ☢️ 🐍
BSD 3-Clause "New" or "Revised" License
199 stars 13 forks source link

Execute notebook programatically has different behavior from running it on a Jupyter Notebook UI #136

Open noklam opened 10 months ago

noklam commented 10 months ago

Context

I am creating a Jupyter magic that will create multiple cells. When I run it manually (i.e. Ctrl + Enter), I can create new cells successfully. When I run it programatically, the code get run without error but the cells are not created.

A gif to show how this magic should behave. image

See: https://github.com/kedro-org/kedro/pull/3510

I am trying to create automated test for this feature, thus it is important to execute this in an automated fashion. I wonder how this is tested

import nbformat
from nbconvert.preprocessors import ExecutePreprocessor

ep = ExecutePreprocessor(timeout=600, kernel_name="python3")
print(f"Executing Notebook {notebook_filename}")
try:
    # Execute the notebook from the same directory
    ep.preprocess(nb,
                  {'metadata': {'path': Path(notebook_filename).parent.resolve()}})

I wonder if you have any idea why it doesn't work, or you can give me some pointers to some relevant tests in this repository. Thank you in advance!