pytest-notebook
A pytest plugin for regression testing and regenerating Jupyter Notebooks.
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:
- Using the pytest test collection architecture.
- As a pytest fixtures (
nb_regression.check(filename)). - Using the
pytest_notebookpython package.
-
All stages are highly configurable via:
- The pytest command-line interface.
- The pytest configuration file.
- The notebook and cell level metadata.
-
Post-processor plugin entry-points, allow for customisable modifications of the notebook, including source code formatting with black
Installation
To install from Conda (recommended):
conda install -c conda-forge pytest-notebook
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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_notebook-0.11.0.tar.gz.
File metadata
- Download URL: pytest_notebook-0.11.0.tar.gz
- Upload date:
- Size: 3.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
008aaa999421174e7945f1a0d8fa7a46bc9d84d961ce23182120be12baa17f8a
|
|
| MD5 |
f51debb33801e9e49c7ca166387b098d
|
|
| BLAKE2b-256 |
a7e97a675397afeef0e2b40c492124c88d56be4e9ef4987ab806ff198678d649
|
Provenance
The following attestation bundles were made for pytest_notebook-0.11.0.tar.gz:
Publisher:
tests.yml on chrisjsewell/pytest-notebook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_notebook-0.11.0.tar.gz -
Subject digest:
008aaa999421174e7945f1a0d8fa7a46bc9d84d961ce23182120be12baa17f8a - Sigstore transparency entry: 2202763437
- Sigstore integration time:
-
Permalink:
chrisjsewell/pytest-notebook@0439a23cfddc097c1dd33f881baaef69c770d2d3 -
Branch / Tag:
refs/tags/v0.11.0 - Owner: https://github.com/chrisjsewell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
tests.yml@0439a23cfddc097c1dd33f881baaef69c770d2d3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pytest_notebook-0.11.0-py3-none-any.whl.
File metadata
- Download URL: pytest_notebook-0.11.0-py3-none-any.whl
- Upload date:
- Size: 40.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
424418c3d8a34868f75a00e35ce3393b34ed2a0fe72f065d34f817938e896d84
|
|
| MD5 |
1b9ad03ba9084122af026c57d7289ca2
|
|
| BLAKE2b-256 |
abeead577a3c5a4d8ae894a9b67011e2c9edfd961e7e21dba0d3f2c4cf12e0ac
|
Provenance
The following attestation bundles were made for pytest_notebook-0.11.0-py3-none-any.whl:
Publisher:
tests.yml on chrisjsewell/pytest-notebook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_notebook-0.11.0-py3-none-any.whl -
Subject digest:
424418c3d8a34868f75a00e35ce3393b34ed2a0fe72f065d34f817938e896d84 - Sigstore transparency entry: 2202763480
- Sigstore integration time:
-
Permalink:
chrisjsewell/pytest-notebook@0439a23cfddc097c1dd33f881baaef69c770d2d3 -
Branch / Tag:
refs/tags/v0.11.0 - Owner: https://github.com/chrisjsewell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
tests.yml@0439a23cfddc097c1dd33f881baaef69c770d2d3 -
Trigger Event:
push
-
Statement type: