Skip to content

Commit

Permalink
fixes #735
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Aug 7, 2022
1 parent c1cf3e5 commit bda89fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 8 additions & 2 deletions nbdev/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
from execnb.shell import *

# %% ../nbs/14_test.ipynb 3
def test_nb(fn, skip_flags=None, force_flags=None, do_print=False, showerr=True):
def test_nb(fn, # file name of notebook to test
skip_flags=None, # list of flags marking cells to skip
force_flags=None, # list of flags marking cells to always run
do_print=False, # print completion?
showerr=True, # warn errors?
basepath=None): # path to add to sys.path
"Execute tests in notebook in `fn` except those with `skip_flags`"
if basepath: sys.path.insert(0, str(basepath))
if not IN_NOTEBOOK: os.environ["IN_TEST"] = '1'
flags=set(L(skip_flags)) - set(L(force_flags))
nb = NBProcessor(fn, nbflags_, process=True).nb
Expand Down Expand Up @@ -86,7 +92,7 @@ def nbdev_test(
if IN_NOTEBOOK: kwargs = {'method':'spawn'} if os.name=='nt' else {'method':'forkserver'}
else: kwargs = {}
results = parallel(test_nb, files, skip_flags=skip_flags, force_flags=force_flags, n_workers=n_workers,
pause=pause, do_print=do_print, **kwargs)
basepath=get_config().config_path, pause=pause, do_print=do_print, **kwargs)
passed,times = zip(*results)
if all(passed): print("Success.")
else:
Expand Down
12 changes: 9 additions & 3 deletions nbs/14_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@
"outputs": [],
"source": [
"#|export\n",
"def test_nb(fn, skip_flags=None, force_flags=None, do_print=False, showerr=True):\n",
"def test_nb(fn, # file name of notebook to test\n",
" skip_flags=None, # list of flags marking cells to skip\n",
" force_flags=None, # list of flags marking cells to always run\n",
" do_print=False, # print completion?\n",
" showerr=True, # warn errors?\n",
" basepath=None): # path to add to sys.path\n",
" \"Execute tests in notebook in `fn` except those with `skip_flags`\"\n",
" if basepath: sys.path.insert(0, str(basepath))\n",
" if not IN_NOTEBOOK: os.environ[\"IN_TEST\"] = '1'\n",
" flags=set(L(skip_flags)) - set(L(force_flags))\n",
" nb = NBProcessor(fn, nbflags_, process=True).nb\n",
Expand Down Expand Up @@ -97,7 +103,7 @@
{
"data": {
"text/plain": [
"0.02000713348388672"
"0.020473957061767578"
]
},
"execution_count": null,
Expand Down Expand Up @@ -193,7 +199,7 @@
" if IN_NOTEBOOK: kwargs = {'method':'spawn'} if os.name=='nt' else {'method':'forkserver'}\n",
" else: kwargs = {}\n",
" results = parallel(test_nb, files, skip_flags=skip_flags, force_flags=force_flags, n_workers=n_workers,\n",
" pause=pause, do_print=do_print, **kwargs)\n",
" basepath=get_config().config_path, pause=pause, do_print=do_print, **kwargs)\n",
" passed,times = zip(*results)\n",
" if all(passed): print(\"Success.\")\n",
" else: \n",
Expand Down

0 comments on commit bda89fa

Please sign in to comment.