Skip to main content

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:

  1. Install from pypi (e.g. with pip):

    pip install pytest-ipynb2
    
  2. That's it! pytest will now collect and execute any tests in jupyter notebooks when run from the command line or IDE.

  3. 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 %%ipytest magic

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:

  • Handling tests grouped into classes #22 (might work - I've not checked yet)
  • v1.0.0 will include dedicated commandline options rather than requiring you to specify the plugin #12

Metadata

Release files for pytest-ipynb2 0.5.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-ipynb2 0.5.0
File Size Uploaded
pytest_ipynb2-0.5.0.tar.gz 21.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-ipynb2 0.5.0
File Interpreter ABI Platform
pytest_ipynb2-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 46.9 kB

Release files / pytest_ipynb2-0.5.0.tar.gz

Download URL pytest_ipynb2-0.5.0.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
413b67929049310df680c469aa322b83f0e7c68b716846072e3dafc0c4bc10fd
BLAKE2b-256 checksum
How to use checksums
497933d07b3fb448954f670b804572bb69a9e3c191bf9b6fb5a12d3f650be2c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Mar 9, 2025.

Transparency log

Release files / pytest_ipynb2-0.5.0-py3-none-any.whl

Download URL pytest_ipynb2-0.5.0-py3-none-any.whl
Size 25.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1af12fc7e00f756efc05dac1841600527cb018fb517a585013d30a089e7536d0
BLAKE2b-256 checksum
How to use checksums
941c4bbd7a96fa327260260e59513828910f7dcbed24ef1642188509bfc37654
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Mar 9, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

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