The functions that grab the cells containing tests (filtering with potential flags) and execute them

Everything that is not an exported cell is considered a test, so you should make sure your notebooks can all run smoothly (and fast) if you want to use this functionality as the CLI. You can mark some cells with special flags (like slow) to make sure they are only executed when you authorize it. Those flags should be configured in your settings.ini (separated by a | if you have several of them). You can also apply flags to one entire notebook by using the all option, e.g. #all_slow, in code cells.

If tst_flags=slow|fastai in settings.ini, you can:

  • mark slow tests with #slow flag
  • mark tests that depend on fastai with the #fastai flag.

Detect flags

The following functions detect the cells that should be excluded from the tests (unless their special flag is passed).

get_all_flags[source]

get_all_flags(cells)

Check for all test flags in cells

nb = read_nb("04_test.ipynb")
assert get_all_flags(nb['cells']) == set()

get_cell_flags[source]

get_cell_flags(cell)

Check for any special test flag in cell

test_eq(get_cell_flags({'cell_type': 'code', 'source': "#hide\n"}), [])

Testing a notebook

class NoExportPreprocessor[source]

NoExportPreprocessor(flags, **kwargs) :: ExecutePreprocessor

An ExecutePreprocessor that executes cells that don't have a flag in flags

test_nb[source]

test_nb(fn, flags=None)

Execute tests in notebook in fn with flags

test_nb('index.ipynb')

nbdev_test_nbs[source]

nbdev_test_nbs(fname:str=None, flags:str=None, n_workers:int=None, verbose:bool_arg=True, timing:bool=False, pause:float=0.5)

Test in parallel the notebooks matching fname, passing along flags

Type Default Details
fname str None A notebook name or glob to convert
flags str None Space separated list of flags
n_workers int None Number of workers to use
verbose bool_arg True Print errors along the way
timing bool False Timing each notebook to see the ones are slow
pause float 0.5 Pause time (in secs) between notebooks to avoid race conditions

nbdev_read_nbs[source]

nbdev_read_nbs(fname:str=None)

Check all notebooks matching fname can be opened

Type Default Details
fname str None A notebook name or glob to convert