fastai / nbdev

Create delightful software with Jupyter Notebooks
https://nbdev.fast.ai/
Apache License 2.0
4.93k stars 487 forks source link

Tests fail even when notebook does not have assert statements #437

Closed lucharo closed 3 years ago

lucharo commented 3 years ago

Hi, first of all, thanks for creating this great tool. I was a bit skeptical at first, but I am amazed at how easy it is to create great code quality with nbdev.

I am raising this issue because I am unable to run nbdev_test_nbs succesfully. I keep getting the following:

testing /home/luis/Projects/my_nbdev_pkg/nbs/00_api.ipynb
Error in /home/luis/Projects/my_nbdev_pkg/nbs/00_api.ipynb:
preprocess() missing 1 required positional argument: 'resources'
testing /home/luis/Projects/my_nbdev_pkg/nbs/01_convert.ipynb
Error in /home/luis/Projects/my_nbdev_pkg/nbs/01_convert.ipynb:
preprocess() missing 1 required positional argument: 'resources'
testing /home/luis/Projects/my_nbdev_pkg/nbs/02_upload.ipynb
Error in /home/luis/Projects/my_nbdev_pkg/nbs/02_upload.ipynb:
preprocess() missing 1 required positional argument: 'resources'
testing /home/luis/Projects/my_nbdev_pkg/nbs/Dummy.ipynb
Error in /home/luis/Projects/my_nbdev_pkg/nbs/Dummy.ipynb:
preprocess() missing 1 required positional argument: 'resources'
testing /home/luis/Projects/my_nbdev_pkg/nbs/index.ipynb
Error in /home/luis/Projects/my_nbdev_pkg/nbs/index.ipynb:
preprocess() missing 1 required positional argument: 'resources'
Traceback (most recent call last):
  File "/home/luis/.config/miniconda3/envs/my_nbdev_pkg/bin/nbdev_test_nbs", line 8, in <module>
    sys.exit(nbdev_test_nbs())
  File "/home/luis/.config/miniconda3/envs/my_nbdev_pkg/lib/python3.9/site-packages/fastcore/script.py", line 105, in _f
    tfunc(**merge(args, args_from_prog(func, xtra)))
  File "/home/luis/.config/miniconda3/envs/my_nbdev_pkg/lib/python3.9/site-packages/nbdev/test.py", line 120, in nbdev_test_nbs
    raise Exception(msg + '\n'.join([f.name for p,f in zip(passed,files) if not p]))
Exception: The following notebooks failed:
00_api.ipynb
01_convert.ipynb
02_upload.ipynb
Dummy.ipynb
index.ipynb

I even created Dummy notebook with no tests in it that fails too.

I am using nbdev1 1.1.13, I am usingnbdev_template` from the 20th of Jan.

My environment is the following: ```bash # packages in environment at /home/luis/.config/miniconda3/envs/my_nbdev_pkg: # # Name Version Build Channel _libgcc_mutex 0.1 main argon2-cffi 20.1.0 py39h27cfd23_1 attrs 20.3.0 pyhd3eb1b0_0 backcall 0.2.0 pyhd3eb1b0_0 beautifulsoup4 4.9.3 pyha847dfd_0 blas 1.0 openblas bleach 3.3.0 pyhd3eb1b0_0 brotlipy 0.7.0 py39h27cfd23_1003 ca-certificates 2021.1.19 h06a4308_0 certifi 2020.12.5 py39h06a4308_0 cffi 1.14.5 py39h261ae71_0 chardet 4.0.0 py39h06a4308_1003 cryptography 3.3.1 py39h3c74f83_1 cycler 0.10.0 py39h06a4308_0 dbus 1.13.18 hb2f20db_0 decorator 4.4.2 pyhd3eb1b0_0 defusedxml 0.6.0 pyhd3eb1b0_0 entrypoints 0.3 py39h06a4308_0 expat 2.2.10 he6710b0_2 fastcore 1.3.19 py_0 fastai fastrelease 0.1.11 pypi_0 pypi fontconfig 2.13.1 h6c09931_0 freetype 2.10.4 h5ab3b9f_0 ghapi 0.1.16 py_0 fastai glib 2.67.4 h36276a3_1 gst-plugins-base 1.14.0 h8213a91_2 gstreamer 1.14.0 h28cd5cc_2 icu 58.2 he6710b0_3 idna 2.10 pyhd3eb1b0_0 importlib-metadata 2.0.0 py_1 importlib_metadata 2.0.0 1 ipykernel 5.3.4 py39hb070fc8_0 ipython 7.20.0 py39hb070fc8_1 ipython_genutils 0.2.0 pyhd3eb1b0_1 ipywidgets 7.6.3 pyhd3eb1b0_1 jedi 0.17.2 py39h06a4308_1 jeepney 0.6.0 pyhd3eb1b0_0 jinja2 2.11.3 pyhd3eb1b0_0 jpeg 9b h024ee3a_2 jsonschema 3.2.0 py_2 jupyter 1.0.0 py39h06a4308_7 jupyter_client 6.1.7 py_0 jupyter_console 6.2.0 py_0 jupyter_core 4.7.1 py39h06a4308_0 jupyterlab_widgets 1.0.0 pyhd3eb1b0_1 jupytext 1.9.1 pyhd3deb0d_1 conda-forge keyring 22.0.1 py39h06a4308_0 kiwisolver 1.3.1 py39h2531618_0 lcms2 2.11 h396b838_0 ld_impl_linux-64 2.33.1 h53a641e_7 libedit 3.1.20191231 h14c3975_1 libffi 3.3 he6710b0_2 libgcc-ng 9.1.0 hdf63c60_0 libgfortran-ng 7.3.0 hdf63c60_0 libopenblas 0.3.10 h5a2b251_0 libpng 1.6.37 hbc83047_0 libsodium 1.0.18 h7b6447c_0 libstdcxx-ng 9.1.0 hdf63c60_0 libtiff 4.1.0 h2733197_1 libuuid 1.0.3 h1bed415_2 libxcb 1.14 h7b6447c_0 libxml2 2.9.10 hb55368b_3 libxslt 1.1.34 hc22bd24_0 lxml 4.6.2 py39h9120a33_0 lz4-c 1.9.3 h2531618_0 markdown-it-py 0.6.1 pyhd8ed1ab_0 conda-forge markupsafe 1.1.1 py39h27cfd23_0 matplotlib 3.3.2 h06a4308_0 matplotlib-base 3.3.2 py39hd261b2b_0 mdit-py-plugins 0.2.4 pyhd8ed1ab_0 conda-forge mistune 0.8.4 py39h27cfd23_1000 nbconvert 5.5.0 py_0 nbdev 1.1.13 pypi_0 pypi nbformat 5.1.2 pyhd3eb1b0_1 ncurses 6.2 he6710b0_1 notebook 6.2.0 py39h06a4308_0 numpy 1.19.2 py39h87658db_0 numpy-base 1.19.2 py39h0f7b65f_0 olefile 0.46 py_0 openssl 1.1.1j h27cfd23_0 packaging 20.9 pyhd3eb1b0_0 pandas 1.2.2 py39ha9443f7_0 pandoc 2.11 hb0f4dca_0 pandocfilters 1.4.3 py39h06a4308_1 parso 0.7.0 py_0 pcre 8.44 he6710b0_0 pexpect 4.8.0 pyhd3eb1b0_3 pickleshare 0.7.5 pyhd3eb1b0_1003 pillow 8.1.0 py39he98fc37_0 pip 21.0.1 py39h06a4308_0 prometheus_client 0.9.0 pyhd3eb1b0_0 prompt-toolkit 3.0.8 py_0 prompt_toolkit 3.0.8 0 ptyprocess 0.7.0 pyhd3eb1b0_2 pycparser 2.20 py_2 pygments 2.8.0 pyhd3eb1b0_0 pyopenssl 20.0.1 pyhd3eb1b0_1 pyparsing 2.4.7 pyhd3eb1b0_0 pyqt 5.9.2 py39h2531618_6 pyrsistent 0.17.3 py39h27cfd23_0 pysocks 1.7.1 py39h06a4308_0 python 3.9.1 hdb3f193_2 python-dateutil 2.8.1 pyhd3eb1b0_0 pytz 2021.1 pyhd3eb1b0_0 pyyaml 5.4.1 py39h27cfd23_1 pyzmq 20.0.0 py39h2531618_1 qt 5.9.7 h5867ecd_1 qtconsole 5.0.2 pyhd3eb1b0_0 qtpy 1.9.0 py_0 readline 8.1 h27cfd23_0 requests 2.25.1 pyhd3eb1b0_0 scipy 1.6.1 py39hf56f3a7_0 seaborn 0.11.1 pyhd3eb1b0_0 secretstorage 3.3.1 py39h06a4308_0 send2trash 1.5.0 pyhd3eb1b0_1 setuptools 52.0.0 py39h06a4308_0 sip 4.19.13 py39h2531618_0 six 1.15.0 py39h06a4308_0 soupsieve 2.2 pyhd3eb1b0_0 sqlite 3.33.0 h62c20be_0 terminado 0.9.2 py39h06a4308_0 testpath 0.4.4 pyhd3eb1b0_0 tk 8.6.10 hbc83047_0 toml 0.10.1 py_0 tornado 6.1 py39h27cfd23_0 traitlets 5.0.5 pyhd3eb1b0_0 tzdata 2020f h52ac0ba_0 urllib3 1.26.3 pyhd3eb1b0_0 wcwidth 0.2.5 py_0 webencodings 0.5.1 py39h06a4308_1 wheel 0.36.2 pyhd3eb1b0_0 widgetsnbextension 3.5.1 py39h06a4308_0 xz 5.2.5 h7b6447c_0 yaml 0.2.5 h7b6447c_0 zeromq 4.3.3 he6710b0_3 zipp 3.4.0 pyhd3eb1b0_0 zlib 1.2.11 h7b6447c_3 zstd 1.4.5 h9ceee32_0 ```

My repo is private for now until I make my first release, so I am unable to share the actual source code, sorry for that. Though I think nbdev_test_nbs should just work based on the examples I've seen and on @hamelsmu 's video demo.

More over, nbdev_build_lib and nbdev_build_docs run fine and I can serve my docs using make docs_serve

hamelsmu commented 3 years ago

Yes - tests also fail on syntax errors, for example, it looks like you are experiencing some syntax error when trying to call your preprocess function from your library. This is because nbdev_test_nbs will run all the code in your notebooks including your tests, so if there are any syntax errors things will fail.

Hope that helps.

lucharo commented 3 years ago

Thanks @hamelsmu for the quick response! That's weird because the notebooks run with no problems. I'll review my code tomorrow,thanks!

hamelsmu commented 3 years ago

I would suggest running a fresh kernel, "restart kernel and run all" may help you see errors locally. Also run nbdev_test_nbs to run all the unit tests locally

lucharo commented 3 years ago

Hi again @hamelsmu, the notebook run with no errors when doing "restart kernel an run all", also the preprocess() function is only present in one notebook, though all notebooks fail.

lucharo commented 3 years ago

I am also wondering, is the tests/ folder special in nbdev? I have one with some sample documents to test my code on and I am wondering if that's causing problem

Note: I changed tests/ to samples/ and change all the path that referred to that folder and I am still getting the same errors

lucharo commented 3 years ago

Ok, I figured it out! My environment was wrong I was using:

nbconvert                 5.5.0                      py_0
nbdev                     1.1.13                   pypi_0    pypi

I think I initially installed nbdev from a location other than the conda fastai channel! I deleted the environment and reinstalled via pip and now things are working:

nbconvert                 5.6.1                      pypi_0    pypi
nbdev                     1.1.13                   pypi_0    pypi

Thanks for the help @hamelsmu! :100:

kheyer commented 3 years ago

I think this issue is due to the version of nbconvert.

I got the exact same error while running nbdev_test_nbs: preprocess() missing 1 required positional argument: 'resources'

However, I didn't have a preprocess function in my code. Upgrading nbconvert to 5.6.1 fixed the problem