Skip to main content

pytest-jupyter

A set of pytest plugins for Jupyter libraries and extensions.

Build Status

Basic Usage

First, install pytest-jupyter from PyPI using pip:

pip install pytest-jupyter

This installs the basic pytest-jupyter package that includes fixture definitions for the various Jupyter-based pytest plugins.

To use one of these plugins, you'll also need to install their dependencies. This requires a second pip install call. For example, if you'd like to use the jupyter_server plugin, you'll need to call:

pip install "pytest-jupyter[server]"

This should install everything you need for the plugin to work.

To use a plugin, add it to the pytest_plugins list in the conftest.py of your project's root test directory.

# inside the conftest.py

pytest_plugins = ["pytest_jupyter.jupyter_server"]

This library includes an echo_kernel, which is useful to speed up testing. You must have either "pytest-jupyter[server]" or "pytest-jupyter[client]" installed to use the echo kernel.

The pytest_jupyter.jupyter_client plugin provides an installed echo_kernel_spec as a fixture, and a start_kernel fixture that provides a factory function that starts a kernel using the echo kernel by default.

Note: The server plugin also includes the client plugin, so you can use both sets of fixtures with "pytest_jupyter.jupyter_server". Both the client and server plugins also include the core fixtures.

Note: The client and server plugins use pytest-tornasync for async test suite running. It may not compatible with pytest-asyncio, meaning that all fixtures must be synchronous. You can use the asyncio_loop fixture and run asyncio_loop.run_until_complete against an async function in your fixtures if needed.

The server fixures use the echo kernel by default. To override this behavior, override the jp_server_config fixture and add the following config:

{
    "MultiKernelManager": {
        "default_kernel_name": "<desired_kernel_name"
    }
}

All fixtures inside the plugin (e.g. jupyter_server) will be available to all of your project's unit tests. You can use a fixtures by passing it as an argument to your unit test function:

async def test_jupyter_server_api(jp_fetch):
    # Send request to a temporary Jupyter Server Web Application
    response = await jp_fetch("api/spec.yml")

    # Confirm that the request is successful.
    assert response.code == 200

You can list the fixtures for a given plugin using the --fixtures argument from the pytest command line interface:

pytest --fixtures -p pytest_jupyter.jupyter_server

or by calling the pytest --fixtures where the plugin is listed in the pytest_plugins variable of a given test directory.

Metadata

Release files for pytest-jupyter 0.11.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-jupyter 0.11.0
File Size Uploaded
pytest_jupyter-0.11.0.tar.gz 15.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-jupyter 0.11.0
File Interpreter ABI Platform
pytest_jupyter-0.11.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.7 kB

Release files / pytest_jupyter-0.11.0.tar.gz

Download URL pytest_jupyter-0.11.0.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a4e08ced44cfea1bce080090c626b8dc4f9d617fa5aafcd84b71405f503e9899
BLAKE2b-256 checksum
How to use checksums
2d9dd32504513eab44d49353280845cf2f68523e6150ab8b5872f8f38fa5ce32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.2.0 CPython/3.12.11

Release files / pytest_jupyter-0.11.0-py3-none-any.whl

Download URL pytest_jupyter-0.11.0-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
677aec971c1e0aa60fb98db248eca4f916f0595012215190028a9e44a8cb64ba
BLAKE2b-256 checksum
How to use checksums
5a7c80ca2226a62eb5562731dba38ee4d3ba0dc293d40cbc45a95a312cc61127
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.2.0 CPython/3.12.11

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

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