Skip to main content

pytest-notebook

CI Coverage RTD PyPI Conda Code style: black

A pytest plugin for regression testing and regenerating Jupyter Notebooks.

Example Test


Purpose

The purpose of the plugin is to ensure that changes to the python environment (e.g. updating packages), have not affected the outputs of the notebook. If the notebook has changed, this plugin can also regenerate the notebooks, saving the new outputs.

Features

  • Recognise, collect, execute (optionally output) then diff input vs. output Jupyter Notebooks.

  • Provides clear and colorized diffs of the notebooks (using nbdime)

  • Regenerate failing notebooks.

  • Integration with coverage and pytest_cov.

  • A well defined API allows notebook regression tests to be run:

    1. Using the pytest test collection architecture.
    2. As a pytest fixtures (nb_regression.check(filename)).
    3. Using the pytest_notebook python package.
  • All stages are highly configurable via:

    1. The pytest command-line interface.
    2. The pytest configuration file.
    3. The notebook and cell level metadata.
  • Post-processor plugin entry-points, allow for customisable modifications of the notebook, including source code formatting with black

Configuration Examples

Installation

To install from Conda (recommended):

>> conda install -c conda-forge pytest-notebook

To install via pip from PyPI:

>> pip install pytest-notebook

To install the development version:

>> git clone https://github.com/chrisjsewell/pytest-notebook .
>> cd pytest-notebook
>> pip install --upgrade pip
>> pip install -e .
>> # pip install -e .[code_style,testing,docs] # install extras for more features

Usage

See the documentation at: http://pytest-notebook.readthedocs.io/

If you want to test some sample notebooks, add the --nb-test-files flag:

>> git clone https://github.com/chrisjsewell/pytest-notebook
>> cd pytest-notebook/examples
>> pip install pytest ipykernel pytest-notebook
>> pytest --nb-test-files *.ipynb

You should see success.ipynb passed the test and fail.ipynb failed the test.

You can regenerate the outputs of fail.ipynb with the --nb-force-regen flag:

>> pytest --nb-test-files --nb-force-regen *.ipynb

Contributing

Contributions are very welcome.

The following will discover and run all unit test:

>> pip install -e .[testing]
>> pytest -v

Coding Style Requirements

The code style is tested using flake8, with the configuration set in .flake8, and code should be formatted with black.

Installing with pytest-notebook[code_style] makes the pre-commit package available, which will ensure these tests are passed by reformatting the code and testing for lint errors before submitting a commit. It can be setup by:

>> cd pytest-notebook
>> pre-commit install

Optionally you can run black and flake8 separately:

>> black .
>> flake8 .

Editors like VS Code also have automatic code reformat utilities, which can adhere to this standard.

License

Distributed under the terms of the BSD-3 license, pytest-notebook is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Acknowledgements

Download files

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

Source Distribution

pytest_notebook-0.8.0.tar.gz (3.4 MB view details)

Uploaded Source

Built Distribution

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

pytest_notebook-0.8.0-py2.py3-none-any.whl (37.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pytest_notebook-0.8.0.tar.gz.

File metadata

  • Download URL: pytest_notebook-0.8.0.tar.gz
  • Upload date:
  • Size: 3.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for pytest_notebook-0.8.0.tar.gz
Algorithm Hash digest
SHA256 7b097bc6f5fc2cf5e6478dd1d74210f481db900472692b815a4af308f09e8402
MD5 33f40b4b5839be6d4c577bb6dc08f9f4
BLAKE2b-256 ef11fdd50dc185ea8335b596a59e84b4068e745d04b6a83450d76f7c07ded056

See more details on using hashes here.

File details

Details for the file pytest_notebook-0.8.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_notebook-0.8.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9b3f17684f384df50383de994d3c6e51a4dbaa08472a8b4b6682029c0907e583
MD5 834ef227fec3a3ed13a09565d6a34b1b
BLAKE2b-256 28cc2d23da68d74f5662b70af2a3288b7e43fb6a2fa4cca5430312dab4456a84

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 Sentry Error logging StatusPage Status page