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).



Check for all test flags in cells

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



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(*args, **kwargs) :: ExecutePreprocessor

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


test_nb(fn, flags=None)

Execute tests in notebook in fn with flags



nbdev_test_nbs(fname:"A notebook name or glob to convert"=None, flags:"Space separated list of flags"=None, n_workers:"Number of workers to use"=None, verbose:"Print errors along the way"=True, timing:"Timing each notebook to see the ones are slow"=False, pause:"Pause time (in secs) between notebooks to avoid race conditions"=0.5)

Test in parallel the notebooks matching fname, passing along flags


nbdev_read_nbs(fname:"A notebook name or glob to convert"=None)

Check all notebooks matching fname can be opened