Open sanfeu opened 1 year ago
I found the way around.
While executing from notebook, sys.path contains root/src
.
While running from testbook, sys.path contains root/
.
I tried to change sys.path in my test.py file, but it has no effect on the notebook execution (I suppose independent kernel is launched).
So what worked for me is to inject a cell at the beginning of the notebook execution thta set my syspath as needed:
tb.inject("""
import sys
sys.path.append('./src')
"""
, before=0, run=False)
I came across this error too but you can set the correct path by configuring the nbclient.NotebookClient which is a parent of TestbookNotebookClient. See also the nbclient docs.
You can update your decorator call to the following:
@testbook('./src/mini_loader.ipynb', execute=True, resources={"metadata": {"path": "src/"}})
This will set the execution path correctly without the need for the injected code. It may be useful to add this to the docs as its not intuitive that testbook should set a different path when compared to executing the notebook directly.
Hello
In my notebook, I import a variable in a py file. While the notebook is running while executed manually, it failed to be executed while using @testbook
The test fails with this error log:
I am working with python 3.9.6, in a venv built directly in the repertory. My environment is
I tried init / play with sys.path but without success. Sorry if I missed something obvious. Can you help?
PS: Thanks a lot for this module, which will probably change the life of my coworkers soon.