Skip to main content

pytest-notebook

CI Coverage RTD PyPI Conda

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 --group test --group pre_commit -e .[docs] # install development dependencies

Usage

See the documentation at: https://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 --group test -e .
pytest -v

Coding Style Requirements

The code style is tested and formatted using ruff, with the configuration set in pyproject.toml.

Installing the pre_commit dependency group (pip install --group pre_commit -e .) makes the pre-commit package available, which will ensure the code style is met by reformatting the code and testing for lint errors before submitting a commit. It can be setup by:

cd pytest-notebook
pre-commit install

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

Release files for pytest-notebook 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-notebook 0.11.0
File Size Uploaded
pytest_notebook-0.11.0.tar.gz 3.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-notebook 0.11.0
File Interpreter ABI Platform
pytest_notebook-0.11.0-py3-none-any.whl Python 3 none any Details

Total release size: 3.5 MB

Release files / pytest_notebook-0.11.0.tar.gz

Download URL pytest_notebook-0.11.0.tar.gz
Size 3.4 MB
Tags Source
SHA-256 checksum
How to use checksums
008aaa999421174e7945f1a0d8fa7a46bc9d84d961ce23182120be12baa17f8a
BLAKE2b-256 checksum
How to use checksums
a7e97a675397afeef0e2b40c492124c88d56be4e9ef4987ab806ff198678d649
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 19, 2026.

Transparency log

Release files / pytest_notebook-0.11.0-py3-none-any.whl

Download URL pytest_notebook-0.11.0-py3-none-any.whl
Size 40.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
424418c3d8a34868f75a00e35ce3393b34ed2a0fe72f065d34f817938e896d84
BLAKE2b-256 checksum
How to use checksums
abeead577a3c5a4d8ae894a9b67011e2c9edfd961e7e21dba0d3f2c4cf12e0ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 19, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.3.1

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page