Skip to main content

Basic notebook checks. Do they run? Do they contain lint?

Project description

See Build Status on Travis CI See Build Status on AppVeyor

nbsmoke

Basic notebook smoke tests: Do they run ok? Do they contain lint?

WARNING: early stage proof of concept; work in progress. Use at your own risk.

In particular, this extension is supposed to handle ipython magics as far as possible, but has not yet been widely tested.


This Pytest plugin was generated with Cookiecutter along with @hackebrot’s Cookiecutter-pytest-plugin template.

Installation

You can install nbsmoke via pip from PyPI:

$ pip install nbsmoke

Or you can install nbsmoke via conda from anaconda.org:

$ conda install -c pyviz/label/dev -c conda-forge nbsmoke

Usage

Check all notebooks in examples/ run without errors:

$ pytest --nbsmoke-run examples/

Check all notebooks in examples/ run without errors, and store html to look at afterwards:

$ pytest --nbsmoke-run --store-html=/scratch examples/

Lint check notebooks in examples/:

$ pytest --nbsmoke-lint notebooks/

Instead of all files in a directory, you can specify a list e.g.:

$ pytest --nbsmoke-run notebooks/Untitled*.ipynb

Additional options are available by standard pytest ‘ini’ configuration in setup.cfg, pytest.ini, or tox.ini:

[pytest]
# when running, seconds allowed per cell (see nbconvert timeout)
cell_timeout = 600

# notebooks to skip running; one case insensitive re to match per line
skip_run = ^.*skipme\.ipynb$
           ^.*skipmetoo.*$

# case insensitive re to match for file to be considered notebook;
# defaults to ``^.*\.ipynb``
it_is_nb_file = ^.*\.something$

nbsmoke supports # noqa comments to mark that something should be ignored during lint checking.

What’s the point?

Although more sophisticated testing of notebooks is possible (e.g. see nbval), just checking that notebooks run from start to finish without error in a fresh kernel (or on a neutral CI service) can be useful during development. Practical experience of working on several projects with notebooks confirms this, but that’s all the evidence I have.

Checking notebooks for lint might seem trivial/pointless, but it frequently uncovers unused names (typically unused imports). It’s also quite common to find python 2 vs 3 problems, and sometimes undefined names - in a way that’s faster than running the notebook (over multiple versions of python).

Unused imports/names themselves might seem trivial, but they can hinder understanding of a notebook by readers, or add dependencies that are not required.

Using # noqa: explanation in a notebook might seem like overkill, but the intention is to encourage unavoidable/desirable ‘mysterious imports’ to be clarified. E.g. if you’re importing something for its side effects, it’s very helpful to inform the reader of that.

Pyflakes is used as the underlying linter because “Pyflakes makes a simple promise: it will never complain about style, and it will try very, very hard to never emit false positives.”

Contributing

First, install using pip install -e .. Then run the tests using tox or pytest -v tests/.

New release to PyPI and anaconda.org: git tag -a vX.Y.Z -m "Something about release" && git push --tags.

License

Distributed under the terms of the BSD-3 license, “nbsmoke” is free and open source software.

Issues

If you encounter any problems, please file an issue (ideally including a copy of any problematic notebook).

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

nbsmoke-0.2.2.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

nbsmoke-0.2.2-py2.py3-none-any.whl (12.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file nbsmoke-0.2.2.tar.gz.

File metadata

  • Download URL: nbsmoke-0.2.2.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for nbsmoke-0.2.2.tar.gz
Algorithm Hash digest
SHA256 7b453243182038739eb12bb5a7ca3ac2bde5c9a3fcb79c9e4dc79df66d593247
MD5 68a5fae8d6ebb2e260b5016bc060909f
BLAKE2b-256 5b7e7f6e4cbb30172c05b8a75119e0fc63e13a5d1ff130a9b8e36c4a1e13f2cc

See more details on using hashes here.

File details

Details for the file nbsmoke-0.2.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for nbsmoke-0.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 eafbbad32ccbb12dd45951ed5d2b7e0a8a5e816be5170a1a69eadc2c7550b9b9
MD5 d3bf8fde93cc895c5dde5aab36962247
BLAKE2b-256 977ee723a212246a5eb51211723d56dde38c2483a9e994fc12f2f5defa9c9aff

See more details on using hashes here.

Supported by

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