Skip to main content

A Pytest plugin to enable Jupyter Notebook testing with Papermill

Project description

pytest-iovis

A plugin that lets you use pytest as a frontend to run and validate Jupyter Notebooks. Comes with some batteries included to get started.

$ pytest notebooks/ --verbose
================================= test session starts ==================================
platform linux -- Python 3.8.18, pytest-7.4.3, pluggy-1.3.0 -- /usr/bin/python3
rootdir: /home/user/Documents/git-repository
plugins: iovis-0.1.0
collected 5 items

notebooks/bar.ipynb::test_notebook_runs PASSED                                    [1/5]
notebooks/baz.ipynb::test_notebook_runs PASSED                                    [2/5]
notebooks/foo.ipynb::test_produces_expected_output PASSED                         [3/5]
notebooks/foo.ipynb::TestMetadata::test_extra_metadata_removed PASSED             [4/5]
notebooks/foo.ipynb::TestMetadata::test_kernelspec_in_allowlist PASSED            [5/5]

================================== 5 passed in 2.63s ===================================

Features

  • Jupyter Notebooks are automatically discovered and run test functions that are user-configurable with directory specific conftest.py files.

Miscellaneous features that help provide a batteries-included experience:

  • A plugin provided default test function that uses papermill to run collected notebooks. This feature is optional and can be enabled by installing the [papermill] extra when installing pytest-iovis.
  • A venv fixture which activates a test-specific virtual environment which has access to all packages from the host environment. Useful when running notebooks that target ipykernel that may try to install packages.

Installation

You can install "pytest-iovis" with its default notebook runner via:

pip install 'pytest-iovis[papermill]'

If the bundled runner is not needed:

pip install 'pytest-iovis'

Note: Installing pytest-iovis does not install any kernels for running notebooks. Users should install notebook kernels separately (e.g. pip install ipykernel).

Getting Started

See docs/getting-started.md.

Contributing

Please see CONTRIBUTING.md for instructions on how to contribute.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Related Projects

  • testbook is a unit testing framework extension for testing code in Jupyter Notebooks. It enables the execution and unit testing of code without needing to modify the Jupyter Notebook itself, so that unit tests can be written using unittest, pytest, or another unit testing framework.

    testbook and pytest-iovis have orthogonal goals, but happen to compliment each other fairly well. Example:

    from testbook import testbook
    
    
    @pytest.fixture()
    def tb(notebook_path: Path):
        with testbook(notebook_path, execute=True) as tb_obj:
            yield tb_obj
    
    
    def test_notebook(tb) -> None:
        func = tb.get("func")
    
        assert func(1, 2) == 3
    
    
    def pytest_iovis_set_tests():
        yield test_notebook
    
  • nbval is a pytest plugin that ensures that a notebook produces output matching the output stored in the notebook.

  • pytest-notebook plugin uses approval/snapshot testing to guard against regressions in notebook output.

Plugin Name

Iovis is the singular genitive case of Iuppiter.

Which is the Latin name of the Roman god Jupiter, from which the planet and Jupyter Notebooks take their namesake.

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

pytest_iovis-0.1.0.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_iovis-0.1.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file pytest_iovis-0.1.0.tar.gz.

File metadata

  • Download URL: pytest_iovis-0.1.0.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pytest_iovis-0.1.0.tar.gz
Algorithm Hash digest
SHA256 67aefa579a1cdd5ab9ede1dd4076f95d61a8b813a28d7d3b27fc98fb0371ede1
MD5 3582dce99febb77c46f9e7598f94e554
BLAKE2b-256 7f01b24ae3e6f044675ee0f85d8c1ee04d7584e6c2131ce195de3b7e72b46419

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_iovis-0.1.0.tar.gz:

Publisher: release.yml on kdestin/pytest-iovis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_iovis-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_iovis-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pytest_iovis-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70195ca95fa23123dee2ac7bd5fc66c253a3f03e1e7454679ed0373b6b2c2743
MD5 b6fab3c9047c9cdbcb949e5847cdb665
BLAKE2b-256 0952853614936a7d76a23da22a0448ebca39402b7c0c5f49abaffa7f38c1f54a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_iovis-0.1.0-py3-none-any.whl:

Publisher: release.yml on kdestin/pytest-iovis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page