Not Sharing variables between Jupyter Notebook nbincludes

I have a set of jupyter notebooks that I would like to execute in a test so as to ensure that they all run:

for file in readdir(NOTEBOOK_DIR)
    if splitext(file)[2] == ".ipynb"
        println("Running ", file)
        nbinclude(joinpath(NOTEBOOK_DIR, file))
    end
end

Unfortunately, imported notebooks will be affected by the code imported by notebooks before them. In Julia 0.7 or 1.0 is it still possible to clear the workspace? Is there an alternative trick I can use?

Include them in separate modules.

1 Like

Thanks fredrikekre, could you please elaborate. Including them as separate modules makes me think my code would be:

module A
    nbinclude("notebookA.ipynb")
end
module B
    nbinclude("notebookB.ipynb")
end
module C
    nbinclude("notebookC.ipynb")
end

While that may work, it isn’t amenable to automatically testing any notebook I put in the directory.

for x in mynotebooks
    m = Module()
    @eval m begin
        using NBInclude
        nbinclude($x)
    end
end

perhaps?

1 Like

Even works in Julia 0.6. Thanks!