Skip to main content

Pytest plugin for testing notebooks

Project description

nbmake

codecov PyPI versions PyPI versions Slack Twitter

What? Pytest plugin for testing and releasing notebook documentation

Why? To raise the quality of scientific material through better automation

Who is this for? Research/Machine Learning Software Engineers who maintain packages/teaching materials with documentation written in notebooks.

Functionality

  1. Executes notebooks using pytest and nbclient, allowing parallel notebook testing
  2. Optionally writes back to the repo, allowing faster building of nbsphinx or jupyter book docs
  3. Optionally builds an HTML report using jupyter-book of the test run which can be uploaded to hosting providers such as Netlify.

Quick Start

pip install pytest nbmake
pytest --nbmake **/*ipynb

Allow errors and Configure Cell Timeouts

nbmake is built on top of nbclient and designed to compatible with nbsphinx and jupyter-book.

The jupyter book docs have a good description of how to ignore errors -- note that nbmake does not work with the external _config.yml configuration file. You must use the notebook JSON metadata field.

Parallelisation

Parallelisation with xdist is experimental upon initial release, but you can try it out:

pip install pytest-xdist

pytest --nbmake -n=auto

It is also possible to parallelise at a CI-level using strategies, see example

Build Jupyter Books Faster

Using xdist and the --overwrite flag let you build a large jupyter book repo faster:

pytest --nbmake --overwrite -n=auto examples
jb build examples

Advice on Usage

nbmake is best used in a scenario where you use the ipynb files only for development. Consumption of notebooks is primarily done via a docs site, built through jupyter book, nbsphinx, or some other means. If using one of these tools, you are able to write assertion code in cells which will be hidden from readers.

Pre-commit

Treating notebooks like source files lets you keep your repo minimal. Some tools, such as plotly may drop several megabytes of javascript in your output cells, as a result, stripping out notebooks on pre-commit is advisable:

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/kynan/nbstripout
    rev: master
    hooks:
      - id: nbstripout

See https://pre-commit.com/ for more...

Disable Nbmake

Implicitly:

pytest

Explicitly:

pytest -p no:nbmake

See Also:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nbmake-0.3.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nbmake-0.3-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file nbmake-0.3.tar.gz.

File metadata

  • Download URL: nbmake-0.3.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for nbmake-0.3.tar.gz
Algorithm Hash digest
SHA256 58766613ec94714f92ea64b991401bfb1d207157c3b18fa1debe4d9913a0a92a
MD5 78c96692e8c22a73775c02449f419d4d
BLAKE2b-256 d04d255d40597a1a83a49145d78ce9372eae4384bd1bbf6b636b5c2adda227b6

See more details on using hashes here.

File details

Details for the file nbmake-0.3-py3-none-any.whl.

File metadata

  • Download URL: nbmake-0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for nbmake-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 05c79eb9459f5fe05fed3fc2d02590eba96204cf4c7cb3d2ed19caf0ea35a223
MD5 2ba70005ac4f63918ed6a26fd8d926ff
BLAKE2b-256 f0ddd16a5c8a9bea09013dd593acc69d3f96065e4e7c606169c2906c4c758730

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page