A pytest plugin for testing Jupyter Notebooks.
Project description
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_notebook
python 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 -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
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file pytest_notebook-0.10.0.tar.gz
.
File metadata
- Download URL: pytest_notebook-0.10.0.tar.gz
- Upload date:
- Size: 3.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a38a73b04c40137402b5f39a053395b418028cb3994a04dbcffe603c7b2a646 |
|
MD5 | 367143980d4254a4c527fb761dbcbc2c |
|
BLAKE2b-256 | 3e038ea56929a6e0675d2c420555b3092c9a74a9a04e70417bcfe5b4b5ef1413 |
File details
Details for the file pytest_notebook-0.10.0-py3-none-any.whl
.
File metadata
- Download URL: pytest_notebook-0.10.0-py3-none-any.whl
- Upload date:
- Size: 37.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 482ab2f8fbac6ecb417226e9b7e68476332262a03f555e49d89a164ee16581f6 |
|
MD5 | 6391ee0d1f88f9e8056a26815fc97ecf |
|
BLAKE2b-256 | 40317ed17c3f929b0b7537ceaab0d06c7ce1d2ec56ddd9dd69306f8bfcd515e8 |