Pytest plugin to run tests in Jupyter Notebooks
Project description
pytest-ipynb2
A pytest plugin to run tests in Jupyter Notebooks.
Designed to play nicely with chmp/ipytest.
Why?
My use case is so that I can teach my son to code and use notebooks to do that but still have the tests show up in vscode test explorer.
We also like to have all our tests run in a github workflow - and this makes that simple too.
Usage
Usage is very simple:
-
Install from pypi (e.g. with pip):
pip install pytest-ipynb2
-
That's it! pytest will now collect and execute any tests in jupyter notebooks when run from the command line or IDE.
-
If you want to run a specific test you can pass it on the command line in the format
pytest path/to/notebook.ipynb[Cell3]::test_name
Test identification
I'm assuming you also want to run your tests inside your notebooks ... so simply use the %%ipytest magic in a cell and pytest will collect any tests based on the usual naming and identification rules.
Note: tests will only be identified in cells which use the
%%ipytestmagic
Documentation
For more details see the docs
Features
-
Enables pytest to collect and execute tests stored within jupyter notebooks
-
Provides meaningful test logs identifying the notebook, cell and test function
-
Handles tests with fixtures and parametrization
-
Executes all cells above the test cell before running the tests in that cell.
WARNING: this means that if any previous cells have side-effects they will occur on test collection, just as they would if included in a pytest test module.
Known limitations & To-Dos
This is an early version. The following things are still on my to-do list:
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
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_ipynb2-0.5.0.tar.gz.
File metadata
- Download URL: pytest_ipynb2-0.5.0.tar.gz
- Upload date:
- Size: 21.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
413b67929049310df680c469aa322b83f0e7c68b716846072e3dafc0c4bc10fd
|
|
| MD5 |
d12f29cca652476c01eea7f2b347aa74
|
|
| BLAKE2b-256 |
497933d07b3fb448954f670b804572bb69a9e3c191bf9b6fb5a12d3f650be2c8
|
Provenance
The following attestation bundles were made for pytest_ipynb2-0.5.0.tar.gz:
Publisher:
publish-python.yml on MusicalNinjaDad/pytest-ipynb2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_ipynb2-0.5.0.tar.gz -
Subject digest:
413b67929049310df680c469aa322b83f0e7c68b716846072e3dafc0c4bc10fd - Sigstore transparency entry: 179460824
- Sigstore integration time:
-
Permalink:
MusicalNinjaDad/pytest-ipynb2@58f9f3d69851dc10b5f18adc1167d3b38ee3631d -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/MusicalNinjaDad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@58f9f3d69851dc10b5f18adc1167d3b38ee3631d -
Trigger Event:
push
-
Statement type:
File details
Details for the file pytest_ipynb2-0.5.0-py3-none-any.whl.
File metadata
- Download URL: pytest_ipynb2-0.5.0-py3-none-any.whl
- Upload date:
- Size: 25.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1af12fc7e00f756efc05dac1841600527cb018fb517a585013d30a089e7536d0
|
|
| MD5 |
ece266dead90a1fbd5ef76b963f83f9e
|
|
| BLAKE2b-256 |
941c4bbd7a96fa327260260e59513828910f7dcbed24ef1642188509bfc37654
|
Provenance
The following attestation bundles were made for pytest_ipynb2-0.5.0-py3-none-any.whl:
Publisher:
publish-python.yml on MusicalNinjaDad/pytest-ipynb2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_ipynb2-0.5.0-py3-none-any.whl -
Subject digest:
1af12fc7e00f756efc05dac1841600527cb018fb517a585013d30a089e7536d0 - Sigstore transparency entry: 179460825
- Sigstore integration time:
-
Permalink:
MusicalNinjaDad/pytest-ipynb2@58f9f3d69851dc10b5f18adc1167d3b38ee3631d -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/MusicalNinjaDad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@58f9f3d69851dc10b5f18adc1167d3b38ee3631d -
Trigger Event:
push
-
Statement type: